【问题标题】:Cleanest way to select items from Richfaces table? Picklist?从 Richfaces 表中选择项目的最简洁方法?选择列表?
【发布时间】:2011-07-26 11:26:40
【问题描述】:
我正在寻找从 Richfaces 表中选择项目的方法。在过去,我使用过复选框。他们把事情搞得一团糟,而且很难维护。选择列表正是我想要的功能类型,但用户将根据多种因素进行选择/选择,因此数据表(或扩展数据表)是有意义的。
从 Richfaces 表中选择项目最简洁的方法是什么?
如果您的答案是选择列表,请详细说明如何合并表格和选择列表功能。
【问题讨论】:
标签:
user-interface
datatable
richfaces
【解决方案1】:
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());
}
}
}