I have a member variable in a managed bean, and this member variable is tied to the component in XHTML with a getter and setter. If I set the member variable in a function call, when the getter of this member variable is trigger, this member variable will still hold the old value. May I know how could I update this member variable so that the component could get the latest updated value?
The manage bean:
@ManagedBean(name = "myBean")
@SessionScoped
public class MyBean {
public boolean show = false;
/** getter and setter **/
public void theFunc() {
this.show = true;
}
}
XHTML code
<h:panelGroup id="Panel_1" rendered="#{myBean.show == true}">
...
Some rubbish here
...
</h:panelGroup>
<h:panelGroup id="Panel_2">
<h:commandLink action="#{myBean.doFunc}">
<f:ajax event="action" render="Panel_1"/>
<h:outputText value="XX" />
</h:commandLink>
</h:panelGroup>
From this sample, the show variable is showing false even though theFunc() has already set to true.
Update on 06 Oct 2012
I have remove commandButton and replace with commandLink, I think it should be fine in term of usage.
Change your methods return type and name if you want it to be invoked.
Change this
to this
otherwise this action can not work.
then update parent of your panel like this
NOTE:
use
instead of