2011-09-02 95 views

回答

0

只需向表示rich:DataTable的行的POJO添加一个布尔值(可能称为selected)即可。并结合这个布尔到<h:selectBooleanCheckbox><rich:dataTable>

例如内<rich:column>,你的豆类,POJO和视图可能看起来喜欢这样的:

<rich:dataTable value="#{myBean.customerList}" var="customer"> 
    <rich:column> 
    <h:selectBooleanCheckbox value="#{customer.selected}" /> 
    </rich:column>  
    <rich:column> 
    <h:outputText value="#{customer.name}" /> 
    </rich:column> 
    <rich:column> 
    <h:outputText value="#{customer.address}" /> 
    </rich:column> 
</rich:dataTable> 


public class MyBean { 

    private List<Customer> customerList; 

    //getter and setter for the customerList 
} 


public class Customer{ 

    private boolean selected; 
    private String name; 
    private String address; 

    //getter and setter for the properties 
} 

要检索选择的行,只是迭代MyBean.customerList并检查Customerselected属性是否为true

0

[已解决]我决定不然。以这种方式添加了一个“Map”和一个带有“CheckBox”的列:“”。通过提交表单,选定的“Map”的行将获得布尔属性等于“true”。

我的豆:

public class Bean<T extends Object> { 
    private Map<T, Boolean> selectedRowsMap = new HashMap<T, Boolean>(0); 
    ... 
    public Set<T> getSelectedRows() { 
     selectedRows.clear(); 
     for (T key : getSelectedRowsMap().keySet()) {   
      if (getSelectedRowsMap().get(key) == true){ 
       selectedRows.add(key);    
      } 
     } 

     return selectedRows; 
    } 
} 

我的XHTML:

<rich:dataTable> 
    <rich:column> 
     <h:selectBooleanCheckbox value="#{bean.selectedRowsMap[row]}" /> 
    </rich:column> 
    <rich:column> 
     <h:outputText value="${row.age}" /> 
    </rich:column> 
    ... 
<rich:dataTable> 
+0

如果解决你的问题,你应该把它标记为答案 – Eonasdan

相关问题