reRender a specific row of rich:dataTable

…衆ロ難τιáo~ 提交于 2019-12-09 00:13:28

问题


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.


回答1:


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 );


来源:https://stackoverflow.com/questions/7227416/rerender-a-specific-row-of-richdatatable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!