Java Code

Java Spring - Richfaces DataTable with CheckBox (Select multiple rows)

I google a lot for this topic and finally found a proper way to make it. It is really easy compare to other solutions for this topic.

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

0 yorum:

Yorum Gönder

Labels