从Richfaces表中选择项目最干净的方法?选择列表?

时间:2011-03-30 22:22:49

标签: user-interface datatable richfaces

我正在寻找从Richfaces表中选择项目的方法。在过去,我使用过复选框。他们弄得一团糟,很难维持。选项列表是我想要的确切类型的功能,但用户将根据许多因素进行选择/选择,因此dataTable(或extendedDataTable)是有意义的。

从Richfaces表中选择项目的最简洁方法是什么? 如果您的答案是选项列表,请详细说明如何合并表格和选项列表功能。

1 个答案:

答案 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());
           }


         }


}