View Full Version : [SOLVED] JSF/Primefaces: Passing values?
fallenshadow
May 23rd, 2012, 10:29 AM
How can a value as in a variable be passed from one webpage to another while executing code to set and get the value?
MyCode:
@ManagedBean(name="TestCodeBean")
public class TestCode {
@ManagedProperty(value = "#{testValue}")
private String testValue;
public String getTestValue() {
return testValue;
}
public void setTestValue(String testValue) {
this.testValue = testValue;
}
On the starting webpage:
<p:inputText value="#{TestCodeBean.testValue}"></p:inputText>
<p:button action="#{TestCodeBean.testValue}" value="TEST ME"></p:button>
On the finishing webpage:
<h:outputText value="#{TestCodeBean.testValue}"></h:outputText>
What am I doing wrong? :?
fallenshadow
May 23rd, 2012, 12:39 PM
As far as I can understand now I just need a proper method to do the transfer and link that to the button.
As for what needs to be in this method I have no idea! :D
r-senior
May 23rd, 2012, 05:50 PM
I've not used JSF with annotations but I don't think you need the @ManagedProperty annotation on the instance variable. The properties are implicitly part of the managed bean without needing further annotations.
I think you'd use that @ManagedProperty annotation to dependency inject another managed bean or static value into your managed bean -- similar to the way you would use Spring "ref" properties to refer to other beans as dependencies.
fallenshadow
May 24th, 2012, 11:02 AM
Can anyone see something wrong with this? :?
<h:commandButton action="#{TestCodeBean.sendData}" />
The error:
Property 'sendData' not found
Method in TestCodeBean:
public String sendData(){
return "/testOutput.xhtml";
}
r-senior
May 24th, 2012, 12:56 PM
The method name needs to be getSendData(). JSF (like JSTL) uses the implied property name rather than the actual name of the getter/setter.
fallenshadow
May 25th, 2012, 10:19 AM
Yes I got things working now!
I have a value from one page being displayed on my other page. :)
Only quite minor problem I have is that the Primefaces widgets are not themed for some reason. They look like plain JSF widgets but I used primefaces ones. (for example - <p:button></p:button>)
Its only a minor issue though... I don't care.. that much but I do like things that look nice! :D
fallenshadow
May 29th, 2012, 10:39 AM
Only quite minor problem I have is that the Primefaces widgets are not themed for some reason. They look like plain JSF widgets but I used primefaces ones. (for example - <p:button></p:button>)
Funny how I am kinda replying to myself but just to let ye know that I fixed this problem too!
Make sure to use <h:head></h:head> tags instead of <head></head> for primefaces! :)
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.