Question

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?

Was it helpful?

Solution

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" />

OTHER TIPS

I agree with Gene but the best way I could find is to surround the content with

<a4j:outputpanel id="whatever_id" />

for example,

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

You rerender the parent. It doesn't have to be a Seam tag.

I suppose that your h:outputText elements on and off are not rendered at load time of the page.

RichFaces will not rerender these components later even if the value of rendered changed to true.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top