Search code examples
ajaxjsfrichfacesrendering

reRender doesn't refresh after event


I just have a selectOneRadio and want to display (or not) a panel depending on the boolean value (basic reRender after an event with a4j). My binding with the boolean is good, and the action confirms that the boolean value changes on clicking:

Here is my selectOneRadio :

<h:selectOneRadio  value="#{myController.myBoolean}">
    <a4j:support event="onclick" action="#{...}"  reRender="myPanel" />
        <f:selectItem itemLabel="Yes" itemValue="#{true}"/>
        <f:selectItem itemLabel="No" itemValue="#{false}"/>
</h:selectOneRadio> 

Why is the reRender not working after using the rendered attribute (no effect) :

<a4j:outputPanel id="myPanel"  rendered="#{myController.myBoolean}">...

whereas it works using style attribute, by changing the visibility :

<a4j:outputPanel id="myPanel"  style="#{myController.myBoolean ? 'visibility:visible;':'display:none;'}">...
  • Richfaces 3.3.3.Final
  • Same bug on every browsers

Solution

  • The problem can be explained as below. Initially your panel "myPanel" is not rendered because rendered attribute is set to false. Then now you change the rendered value to true by selecting the selectOneRadio component. Then you are going to reRender the "myPanel" by using reRender="myPanel" in your a4j:support tag.
    But unfortunately there is no "myPanel" to be reRendered because there is no such element in your page(because it is not rendered).

    You can overcome this issue by reRendering the parent of the "myPanel". For an example if "myPanel" has a parent panel as below,

    <a4j:outputPanel id="parentPanel">
        <a4j:outputPanel id="myPanel"  rendered="#{myController.myBoolean}">
               .......
        </a4j:outputPanel>
    </a4j:outputPanel>
    

    Now reRender the parent as below

    <a4j:support event="onclick" action=#{...}"  reRender="parentPanel" />
    

    Note: When you change the visibility instead of rendered attribute, it works because although "myPanel" is hidden it is still available in your page.