How to re-render a RichFaces component after a4j link is invoked

Aaron Chambers picture Aaron Chambers · Jul 10, 2009 · Viewed 27.4k times · Source

Hoping someone can help me with a slight hurdle I've come up against in regards to re-rendering of RichFaces components after an a4j link/button has performed it's action. A simplified version of my problem is as follows:

I have 2 output components displaying a text value which are rendered based on some value in my manager class:

<h:outputText id="on" value="ON" rendered="#{manager.isOn}" />

<h:outputText id="off" value="OFF" rendered="#{not manager.isOn}" />

I also have 2 a4j links that call some action and then re-render the above outputText components:

<a4j:commandLink ajaxSingle="true" value="Set On" action="#{manager.setOn(true)}" reRender="on,off" />

<a4j:commandLink ajaxSingle="true" value="Set Off" action="#{manager.setOn(false)}" reRender="on,off" />

What I would expect to happen is, when I click the 'Set On' button, the 'ON' outputText component would unhide, and the 'OFF outputText component would show. However, this does not happen.

Does anyone have the answer as to why this is so, and how I go about re-rendering these components after the a4j component action has completed?

Answer

Aaron Chambers picture Aaron Chambers · Jul 10, 2009

Wrap the outputText components in an s:div and re-render that as follows:

<s:div id="myDiv">
    <h:outputText id="on" value="ON" rendered="#{manager.isOn}" />

    <h:outputText id="off" value="OFF" rendered="#{not manager.isOn}" />
</s:div>

<a4j:commandLink ajaxSingle="true" value="Set On"
   action="#{manager.setOn(true)}" reRender="myDiv" />

<a4j:commandLink ajaxSingle="true" value="Set Off"
   action="#{manager.setOn(false)}" reRender="myDiv" />