4

Good Morning!

Is it possible to reRender only 1 specific row of rich:dataTable?

I have a rich:dataTable and, when I do something that I´m sure only 1 row has changed, I need to reRednder only this row, not the entire table. Is it possible? How?

XHTML:

<rich:dataTable id="myTable"  value="#{bean.table}" var="me">
    <rich:column>
        <h:outputText value="#{me.id}" />
    </rich:column>
    <rich:column>
        <h:outputText value="#{me.valueOne}" />
    </rich:column>
    <rich:column>
        <h:outputText value="#{me.valueTwo}" />
    </rich:column>
</rich:dataTable>

<some:tag.... reRender="??????" action="bean.example" />

Java:
public void example{
   // Do something that affects to the row selected
}

THANK YOU VERY MUCH.

ganzux
  • 874
  • 3
  • 15
  • 35

1 Answers1

4

Yes , it is possible . You have to specify the followings things:

  • Which columns to be rendered via the reRender attribute of the tags that can invoke MBean method
  • What rows to be rendered via the ajaxKeys attribute of the rich:dataTable .

The ajaxKeys attribute is bound to Set <Integer> Object which holds the row numbers to be updated.

For example , suppose you want to invoke a Mbean method using a4j:commandButton and want to render a particular row and column after the action finishes . You can use the following :

<a4j:commandButton action="#{bean.someAction}"  reRender="columnID,columnID2">
    <f:setPropertyActionListener value="#{idx}" target="#{bean.selectedRow}" />
</a4j:commandButton>

 <rich:dataTable id="myTable"  value="#{bean.table}" var="me" ajaxKeys="#{bean.rowsToUpdate}" rowKeyVar="idx">
        <rich:column id="columnID">
            <h:outputText value="#{me.id}" />
        </rich:column>
        <rich:column id="columnID2">
            <h:outputText value="#{me.valueOne}" />
        </rich:column>
        <rich:column>
            <h:outputText value="#{me.valueTwo}" />
        </rich:column>
    </rich:dataTable>

Inside the bean.someAction() , you add the row number that you want to update to the rowsToUpdate integer set:

HashSet<Integer> rows = new HashSet<Integer>();
rows.add(selectedRow);
setRowsToUpdate( rows );
ganzux
  • 874
  • 3
  • 15
  • 35
Ken Chan
  • 84,777
  • 26
  • 143
  • 172
  • **Ken Chan**, it works! Thank you very much!!!! Only one thing: I must to use the **rowKeyVar** attribute from the **dataTable** to know what row is selected :) --> Again, THANKS. – ganzux Aug 30 '11 at 11:26
  • Hello. I want to execute only one row, send to server just information of one row and not all table? – Fernando Pie Jun 21 '18 at 16:23