hi group,
it is common usecase for web-application to be able to select items
(rows) of datatable and choosing desired action from a choice.
to solve this issue, i personally using often the following construct :
(the 'adapter' backing bean serves all necessary data)
<t:dataTable id="myTableData" styleClass="myTableStyle"
binding="#{adapter.uiData}" headerClass="tableHeader"
footerClass="tableFooter"
columnClasses="col0,col1, [...]" var="item"
value="#{adapter.itemList}"
preserveDataModel="false"
rowId="#{item.id}" rowIndexVar="idx"
rowStyleClass="row#{(idx%2==0)?'0':'1'}"
sortColumn="#{adapter.sort}" //
sortAscending="#{adapter.ascending}"
preserveSort="true">
<h:column>
<f:facet name="header">
<t:commandSortHeader
columnName="id" arrow="false">
<f:facet name="ascending">
<t:graphicImage value="arrow_down.png" />
</f:facet>
<f:facet name="descending">
<t:graphicImage value="arrow_up.png" />
</f:facet>
<h:outputText value="#{bundle['item.id']}" />
</t:commandSortHeader>
<t:selectOneRadio
valueChangeListener="#{adapter.processValueChange}"
id="rowSelector" forceId="true" forceIdIndex="false"
layout="spread" value="select">
<f:selectItems value="#{adapter.selectItemList}"/>
</t:selectOneRadio>
</f:facet>
<t:radio for="rowSelector" index="#{idx}"></t:radio>
<h:outputText value="[#{item.id}]" />
</h:column>
[...]
But this approach has a big disadvantage : the method 'selectItemList'
is called in every rendered row even though the list themself isn't
change. So if method has to build up a list-object, it takes long time
to render especially large table.
By the way, there is another thing i want to mentioned here : the
SelectItem-class, which you have to use, when using
selection-components. IMHO this has to be a interface, since we are all
aware of the multiple inheritance issue with java.
Its often the case that the objects, you going display inside the table
already have their inheritance tree. And it is difficult and timewasting
to implement method for just serving SelectItem-lists.
Particularly there is 'nothing' to do to implement this interface.
so far, comments appreciate, thank you in advance
ronald