在af:table中,通常我們做的是一次選中一行,然後點選綁定了Delete operation的按鈕,可以删除選中的行。下面介紹如何一次選中多行,并實作删除多行的邏輯。
1,建立Fuwion Web Applicaiton
2,Model層使用HR schema的departments表,建立EO、VO,并将VO對象Expose給UI。
3,建立頁面,将departments VO以table形式展示到頁面上,注意要選擇‘Multiple Rows’。
4,建立Managed Bean,并建立RichTable對象,将頁面上的af:table綁定到該RichTable對象
view plain copy to clipboard print ?
- <af:table value="#{bindings.DepartmentsView1.collectionModel}" var="row"
- rows="#{bindings.DepartmentsView1.rangeSize}"
- emptyText="#{bindings.DepartmentsView1.viewable ? 'No data to display.' : 'Access Denied.'}"
- fetchSize="#{bindings.DepartmentsView1.rangeSize}" rowBandingInterval="0"
- selectionListener="#{bindings.DepartmentsView1.collectionModel.makeCurrent}" rowSelection="multiple"
- id="t1" binding="#{backingBeanScope.backing_departments.tblDept}">
[html] view plain copy print ?
- <af:table value="#{bindings.DepartmentsView1.collectionModel}" var="row"
- rows="#{bindings.DepartmentsView1.rangeSize}"
- emptyText="#{bindings.DepartmentsView1.viewable ? 'No data to display.' : 'Access Denied.'}"
- fetchSize="#{bindings.DepartmentsView1.rangeSize}" rowBandingInterval="0"
- selectionListener="#{bindings.DepartmentsView1.collectionModel.makeCurrent}" rowSelection="multiple"
- id="t1" binding="#{backingBeanScope.backing_departments.tblDept}">
<af:table value="#{bindings.DepartmentsView1.collectionModel}" var="row"
rows="#{bindings.DepartmentsView1.rangeSize}"
emptyText="#{bindings.DepartmentsView1.viewable ? 'No data to display.' : 'Access Denied.'}"
fetchSize="#{bindings.DepartmentsView1.rangeSize}" rowBandingInterval="0"
selectionListener="#{bindings.DepartmentsView1.collectionModel.makeCurrent}" rowSelection="multiple"
id="t1" binding="#{backingBeanScope.backing_departments.tblDept}">
5,在Mnage Bean中建立方法removeMultiselectRows,如下:
view plain copy to clipboard print ?
- public void removeMultiselectRows(ActionEvent event) {
- RowKeySet rowKeySet = tblDept.getSelectedRowKeys();
- CollectionModel cm = (CollectionModel)tblDept.getValue();
- for (Object facesTreeRowKey : rowKeySet) {
- cm.setRowKey(facesTreeRowKey);
- JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding)cm.getRowData();
- rowData.getRow().remove();
- }
- }
[java] view plain copy print ?
- public void removeMultiselectRows(ActionEvent event) {
- RowKeySet rowKeySet = tblDept.getSelectedRowKeys();
- CollectionModel cm = (CollectionModel)tblDept.getValue();
- for (Object facesTreeRowKey : rowKeySet) {
- cm.setRowKey(facesTreeRowKey);
- JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding)cm.getRowData();
- rowData.getRow().remove();
- }
- }
public void removeMultiselectRows(ActionEvent event) {
RowKeySet rowKeySet = tblDept.getSelectedRowKeys();
CollectionModel cm = (CollectionModel)tblDept.getValue();
for (Object facesTreeRowKey : rowKeySet) {
cm.setRowKey(facesTreeRowKey);
JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding)cm.getRowData();
rowData.getRow().remove();
}
}
6,頁面上的按鈕綁定removeMultiselectRows方法
view plain copy to clipboard print ?
- <af:commandToolbarButton text="RemoveRows" id="ctb1"
- actionListener="#{backingBeanScope.backing_departments.removeMultiselectRows}"/>
[html] view plain copy print ?
- <af:commandToolbarButton text="RemoveRows" id="ctb1"
- actionListener="#{backingBeanScope.backing_departments.removeMultiselectRows}"/>
<af:commandToolbarButton text="RemoveRows" id="ctb1"
actionListener="#{backingBeanScope.backing_departments.removeMultiselectRows}"/>
7,運作,效果如下:
多選行,要按住Ctrl鍵:
點RemoveRows按鈕:
Commit儲存到資料庫,Rollback回退。