Search code examples
ajaxjsfdatatablerichfacesuirepeat

How to reRender a rich:dataTable which is inside a4j:repeat?


I have sth like this:

<a4j:repeat value="#{results}" var="hdr" rowKeyVar="idx">
   <rich:dataTable var="item" value="#{results}" id="tbl#{idx}" first="#{idx}" rows="1">
       <a4j:commandButton value="update this table only" reRender="tbl#{idx}" />
   </rich:dataTable>
</a4j:repeat>

When I check from the output html, the data table has id like form:0:tbl that has no idx at the end.

The reRender will work when there is only one row in the results.

So here comes some questions:

  1. Why doesn't dataTable's id works with EL expression while the "first" attribute works nicely?
  2. How does reRender work that even I just specify tbl it can still be resolved while the actual HTML id is something longer like form:0:tbl? (if I know how does reRender work, I maybe able to hack it to work with a4j:repeat...)
  3. Is there any technique or workaround that I could use to refresh only a specific dataTable that is inside a4j:repeat?

In fact I have successfully reRendered the whole a4j:repeat block surrounded by s:div. But refreshing the whole block would reset the scrollbar so it isn't desired....


Solution

  • Okay latest experiment shows that simply using the rich:dataTable id can do.

    Keys to remember:

    1. Inside a4j:repeat, the absolute name of the id of dataTable will have something like :0: :1: for the corresponding index.
    2. However, to locate it, simply using the same id as defined in rich:dataTable is okay. Don't append any suffix at the end.
    3. When observing the ajax data from Chrome, the reRendered portion is just the same related dataTable of the component.

    Conclusion, think too much, failed to try the simplest solution at the start.