views:

4382

answers:

6

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?

+2  A: 

Finally found out how to do it. And it's bloody simple.

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" />
Aaron Chambers
A: 

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.

Daniel Murygin
A: 

Is there a solution to this issue without using SEAM?

Wrapping the components in an a4j:outputPanel corrected this issue.
A: 

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

A: 

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>
Gubbes
A: 

I have a similar issue while rendering dataTable. I have a commandLink in the dataTable through which Rich modalPanal is invoked for adding new rows in the dataTable.

My issue is that the rendering of dataTable occurs before the action method actually completes. The datatable is bound with collection that is updated in the java code before the actual database updates occurs.

This bring inconsistency in order of the data rendered onto the table and actual data in the collection which changes its value once the database is actually affected.

Neeraj