views:

84

answers:

0

I'm using a to display an array of my domain objects (POJO) in my web page, like this:

<rich:dataTable id="instanceListTable" value="#{instanceListBean.runningProcesses}" var="instance">

The dataTable generates client IDs based on the index in the array, which is later used to identified the row that user selected. The problem is, the order / set of entities can be changed between requests, and such selection can be wrong.

For example, I've put a link for removing an entity on the table:

<rich:column>
    <f:facet name="header"><h:outputText value="Actions"/></f:facet>
    <a4j:commandLink id="terminateLink"
                     action="#{instanceListBean.doTerminateInstance}"
                     ajaxSingle="true"
                     immediate="true"
                     reRender="listPanel">
        <f:setPropertyActionListener value="#{instance.id}"
                                     target="#{instanceListBean.selectedInstanceId}"/>
        <h:outputText value="Terminate"/>
    </a4j:commandLink>
</rich:column>

As you can see, I'm using <f:setPropertyActionListener> that works in server side. So, the data is reloaded on post back, and the ID is looked up using the index of the row. If another user has removed another row between the request, the selected row will not be the same row as the user intended.

I want to use my domain object's ID instead of row# for identifying, but I don't seem to find an easy way to do so.

What I expected was an attribute to do so, like rowKeySelector="#{instance.id}'. But I couldn't find such a thing.

There's a rowKeyConverter attribute, that I'm not sure how to use, and seems not easy at all. Another solution is to implement ExtendedDataModel and override getRowKey and setRowKey, ... but that's not easy either. Another hack is to use JavaScript in client side to fill some inputs outside the table and submit the form, but that's not a clean solution at all.

I expect something like this to be very primitive and easy to do, but I don't seem to find a satisfactory solution, or maybe I'm wrong about something.

Edit: I forgot to say: changing the bean's scope to Session is not an option, due to the scalability / functionality issues.

Edit: Maybe I'm not clear with the question. What's the easiest way to use domain identifiers as the row keys in rich:dataTable?