JSF ReRender support with selectBooleanCheckbox

I have a JSF page where I want to set a checkbox which, when clicked, will add / remove some other form fields from the page. Here is the code (simplified) that I have for this checkbox:

<h:selectBooleanCheckbox title="showComponentToReRender" value="#{backingBean.showComponentToReRender}">
    <a4j:support event="onsubmit" reRender="componentToReRender" />
</h:selectBooleanCheckbox>

Here is the code for the component I want to hide:

<h:selectOneMenu id="componentToReRender" value="#{backingBean.value}" rendered="#{valuesList.rowCount>1 &amp;&amp; backingBean.showComponentToReRender}">
   <s:selectItems value="#{valuesList}" var="value"/>
</h:selectOneMenu>

Clicking the checkbox currently does nothing; that "selectOneMenu" will not disappear. What am I doing wrong?

+3
source share
2 answers

You need to wrap componentToReRenderin:

<h:panelGroup id="componentToReRenderWrapper">

or

<a4j:outputPanel id="componentToReRenderWrapper">

So you will have:

<h:panelGroup id="componentToReRenderWrapper">
    <h:selectOneMenu id="componentToReRender" value="#{backingBean.value}" rendered="#{valuesList.rowCount>1 &amp;&amp; backingBean.showComponentToReRender}">
       <s:selectItems value="#{valuesList}" var="value"/>
    </h:selectOneMenu>
</h:panelGroup>

and change reRender="componentToReRenderWrapper"if you use panelGroup, or remove this attribute if you use outputPanel.

RichFaces docs:

reRender , "rendered" . , JSF DOM , , "rendered" false. , Ajax, RichFaces , , . , "rendered" . layout = "none".

+9

ajaxRendered = "true" a4j: outputPanel

+2

Source: https://habr.com/ru/post/1727795/


All Articles