I have two variables "userId" and "name". When I click for example the "SHOW USERID" button it works fine and sets "renderUserId=true" and it shows it with the "render", but then if I click the other "SHOW" button, the Bean is reconstruct and I loose the "renderUserId=true" and it becomes "false" and "renderName=true" so it shows ok, but the USERID is hidden.
My question is, how can I avoid loosing the bean values when I render the xhtml?
This is a simple simulation of my code.
NOTE: if I use "actionListener" instead of "f:setPropertyActionListener" in the "h:commandButton" I have the same result, the bean is reconstruct
example.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:cc="http://java.sun.com/jsf/composite">
<cc:interface componentType="com.bean.ExampleBean">
<cc:attribute name="userId" type="java.lang.Integer"/>
<cc:attribute name="name" type="java.lang.String"/>
</cc:interface>
<cc:implementation>
<h:panelGrid id="example_panel" columns="1" width="100%">
<h:outputText value="USERID: #{cc.attrs.userId}" rendered="#{!cc.attrs.renderUserId}"/>
<a4j:commandButton value="SHOW USERID" render="example_panel"
rendered="#{!cc.attrs.renderUserId}">
<f:setPropertyActionListener value="#{true}"
target="#{cc.attrs.renderUserId}"/>
</a4j:commandButton>
<a4j:commandButton value="HIDE USERID" render="example_panel"
rendered="#{cc.attrs.renderUserId}">
<f:setPropertyActionListener value="#{false}"
target="#{cc.attrs.renderUserId}"/>
</a4j:commandButton>
<h:outputText value="NAME: #{cc.attrs.name}" rendered="#{!cc.attrs.renderName}"/>
<a4j:commandButton value="SHOW NAME" render="example_panel"
rendered="#{!cc.attrs.renderName}">
<f:setPropertyActionListener value="#{false}"
target="#{cc.attrs.renderName}"/>
</a4j:commandButton>
<a4j:commandButton value="HIDE NAME" render="example_panel"
rendered="#{cc.attrs.renderName}">
<f:setPropertyActionListener value="#{false}"
target="#{cc.attrs.renderName}"/>
</a4j:commandButton>
</h:panelGrid>
</cc:implementation>
</ui:composition>
ExampleBean.java
import javax.faces.component.FacesComponent;
import javax.faces.component.UINamingContainer;
@FacesComponent("com.bean.ExampleBean")
public class ExampleBean extends UINamingContainer {
private Integer userId;
private String name;
private boolean renderUserId;
private boolean renderName;
}