我正在寻找从Richfaces表中选择项目的方法。在过去,我使用过复选框。他们弄得一团糟,很难维持。选项列表是我想要的确切类型的功能,但用户将根据许多因素进行选择/选择,因此dataTable(或extendedDataTable)是有意义的。
从Richfaces表中选择项目的最简洁方法是什么? 如果您的答案是选项列表,请详细说明如何合并表格和选项列表功能。
答案 0 :(得分:3)
rich:extendedDataTable
有一个属性selection
可绑定到MBean中保存所选行的变量。此变量应为org.richfaces.model.selection.Selection
您的rich:extendedDataTable
也应该允许您选择多行,这可以通过将selectioMode
属性指定为multi
所以,你rich:extendedDataTable
应该喜欢:
<rich:extendedDataTable value="#{mBean.custList}" selection="#{mBean.selection}" selectionMode="multi" >
在Mbean中,您可以访问mBean.selection
变量中的选定行:
public class Mbean {
//List to be displayed to the rich:extendedDataTable
private List<Customer> custList ;
//Variable to hold the selected row
private SimpleSelection selection;
/*
Getter and setter of the custList and selection
*/
public void someMethod(){
//Code snippets to access the selected rows
Iterator<Object> iterator = this.selection.getKeys();
while (iterator.hasNext()){
Integer key = (Integer) iterator.next();
Customer cust = (Customer) this.custList.get(key);
System.out.println(cust.toString());
}
}
}