I have a JSF 2 form like this:
<h:form>
<h:panelGrid columns="2">
<a4j:repeat value="#{dialog.departments}" var="depart">
<h:inputText value="#{depart.name}"/>
<h:selectOneRadio value="#{depart.hasSubdepartment}">
<f:ajax render="@form" execute="@form" immediate="true"/>
<f:selectItem itemValue="#{true}"/>
<f:selectItem itemValue="#{false}"/>
</h:selectOneRadio>
<a4j:repeat value="#{depart.subdepartments}" var="sub" rendered="#{depart.hasSubdepartment}">
<h:inputText value="#{sub.name}"/>
<h:outputText value=" " />
</a4j:repeat>
</a4j:repeat>
</h:panelGrid>
</h:form>
I have simply the form. As you could see, this form displays data structure of departments like a tree.
What I want to implements is that if user switch the radio button to true
, the sub-departments will be displayed, if switch to false, the sub-departments will be hidden.
The problem is that:
- If the
execute
value of thef:ajax
tag is set to@form
, the validation of the backing beans such as@NotNull
and@Size
will be called. But we don't want to call the validation now since we do not want to save the data now. - If the
execute
value of thef:ajax
tag is set to@this
, it seems that the after the ajax request, the value of the radio reverts. For example, if the radio value isfalse
, and we clicktrue
, then after the ajax request, the value go back tofalse
, and the sub-department part is not rendered. This will not happen ifexecute
is set to@form
.
Thanks very much if you have any idea or hint.
I don't have a Richfaces integrated testing environment, however I've achieved what you want in plain JSF (that's why it could be an ajax4jsf specific issue). Here you have a test case which works and follows SSCCE standards. Tested with Mojarra 2.1.26 & Tomcat 6: