There is a class named org.springframework.faces.model.ManySelectionTrackingListDataModel in Spring lib and it can be use for multiple select like this.
xhtml code:
<rich:dataTable id="rDataTable" value="#{dataList}" var="var" >
<rich:column width="#{checkboxWidth}">
<f:facet name="header">
<h:outputText value="" />
</f:facet>
<h:selectBooleanCheckbox id="select" value="#{dataList.currentRowSelected}"/>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="DataLabel" />
</f:facet>
<h:outputText value="#{var.data}" />
</rich:column>
</rich:dataTable>
Get copy of org.springframework.faces.model.ManySelectionTrackingListDataModel and add this code in it.
public void setCurrentRowSelected(boolean rowSelected) {
if (!isRowAvailable()) {
return;
}
if (rowSelected && !selections.contains(getRowData())) {
selections.add(getRowData());
} else if(!rowSelected && selections.contains(getRowData())){
selections.remove(getRowData());
}
}
After that just set result-type of your data list to your copy of ManySelectionTrackingListDataModel
flow xml code:
... <view-state id="dataList" view="/pages/dataList.xhtml"> <on-render> <evaluate expression="dataList.getData()" result="flowScope.dataList" result-type="com.foo.ManySelectionTrackingListDataModel" /> </on-render> ... </view-state> ...
Links
- http://forum.springsource.org/showthread.php?t=65823
- http://forum.springsource.org/showthread.php?t=66668
- http://www.javabeat.net/tips/43-how-to-use-hselectbooleancheckbox-within-hd.html
- http://balusc.blogspot.com/2006/06/using-datatables.html#SelectMultipleRows