0 Replies Latest reply on Jan 26, 2010 4:27 PM by flopsi

    rich:dataTable with h:commandLink, pagination problem

    flopsi
      Hi all,
      i have a problem to get a selected item from a paginated dataTable via an action method.
      Here's what i tried (simplified):

      <rich:dataTable id="..." var="_resultObj" value="#{entityListObj.resultList}" rendered="#{entityListObj.resultCount > 0}">
        <rich:column styleClass="action">
          <f:facet name="header">ID</f:facet>
            <h:outputText value="#{resultObj.id}"/>
          </f:facet>
        </rich:column>
        <rich:column styleClass="action">
          <f:facet name="header">Action</f:facet>
            <h:commandLink action="#{entityListObj.select(resultObj.id)}" value="Select"/>
          </f:facet>
        </rich:column>
      </rich:dataTable>

      If the list is not paginated, everything works fine, but if it is (using Query.firstResult and Query.maxResults), the ids passed to the select method are always the ids of the first page (for every page).
      For example, if the first page looks like this:

      id ...
      1  ...
      5  ...
      9  ...

      and the second like this:

      id ...
      10 ...
      11 ...
      12 ...

      and i e.g. click on the third item on the second page, which obviously has the id 12, the value passed to the select method is 9. If i click the first item on the second page, a 1 is passed. And so on.
      I read a lot web stuff but could not find a clear solution. Some posts say that dataTable changes the ids of the commandLinks while rendering and therefore sometimes runs into problems.
      By the way, using indirection via page-params and -actions

      <s:link view="/#{from}.xhtml" value="Select" propagation="join">
        <f:param name="#{resultObjId}" value="#{resultObj.id}"/>
      </s:link>

      <param name="resultObjId" value="#{entityListObj.selectedId}"/>
      <action execute="#{entityListObj.select()}"/>

      works at this point, but leads me into other problems... I also tried to fetch the id in the action method via getDataModelSelection(), but same result: ids are the ones of the first page.
      Maybe some kind of timing problem?!? I know that h:commandLink does a postback while s:link does not, but what are the implications, and are there other differences?
      When is resultObj.id evaluated exactly? I think the evaluation in case of s:link is done one request earlier to be able to render the link (Render Response Phse), while in the case of h:commandLink it is evaluated after the postback, directly before the action method call (Invoke App Phase)?!?

      Your ideas are greatly appreciated
      Thanks a lot
      Flo