Reputation: 6979
I have an inputText object in JSF, let say inputText_A, and the value is bind to the session Bean object's member variable. It is a type of double.
<h:inputText value="#{theBean.theMemberVar}" />
And this inputText_A has been initialize to 0.0. When theBean is performing a calculation, the value will be updated back to theBean.theMemberVar. I have trace it back in the debug console and the value has been updated to my expected value. But the inputText_A at the screen still showing original value, which is 0.0.
I have tested using outputText, my expected output is showing there but it become read only on the screen after that. I want it to be editable after my expected output has populate into inputText_A, thus I choose inputText object.
I understand that when we pass some value from JSF to Bean, we use inputText, and when some value is pass out from Bean to JSF, we use outputText. But now I want to pass the value from Bean to JSF using inputText. May I know can this be done?
Upvotes: 0
Views: 3420
Reputation: 2427
It is completely fine to display some updated value via h:inputText
(if you need such functionality). You just have to have appropriate getter
and setter
for the bean variable.
So for example :
private String text;
// here you will update the input text - in your case method which does calculations
public void changeText(){
...
text = "updated";
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
And your facelet (.xhtml) :
<h:inputText value="#{dummyBean.text}" />
<h:commandButton value="Change text" actionListener="#{dummyBean.changeText}" />
Your inputText
will be updated on button click.
Other thing is if you are updating your content via Ajax. Then you need to re-render the parent component
of the inputText
or the form
of the inputText
:
<h:commandButton immediate="true" value="Change text">
<f:ajax event="click" render=":formID" listener="#{dummyBean.changeText}"/>
</h:commandButton>
Upvotes: 2