当前位置: 代码迷 >> JavaScript >> JSF的dataTable应用selectBooleanCheckbox
  详细解决方案

JSF的dataTable应用selectBooleanCheckbox

热度:19   发布时间:2012-09-15 19:09:29.0
JSF的dataTable使用selectBooleanCheckbox
JSF
<h:form>
    <h:dataTable value="#{myBean.dataList}" var="item">
        <h:column>
            <f:facet name="header">
                <h:outputText value="Select" />
            </f:facet>
            <h:selectBooleanCheckbox value="#{myBean.selectedIds[item.id]}" />
        </h:column>
          ...
    </h:dataTable>
    <h:commandButton value="Get selected items" action="#{myBean.getSelectedItems}" />
</h:form>


后台Bean
public class MyBean ...{
    private Map selectedIds = new HashMap();
    private List selectedDataList;
    public String getSelectedItems() ...{
         selectedDataList = new ArrayList();
        for (MyData dataItem : dataList) ...{
            //如果使用了分页的话这个判断不可少.
            if(selectIds.get(dataItem.getId())==null)...{  
                continue;
             }
            if (selectedIds.get(dataItem.getId()).booleanValue()) ...{
                 selectedDataList.add(dataItem);
                 selectedIds.remove(dataItem.getId()); // 删掉已取的项.
             }
         }
        // 这里加需要处理的代码, 比如批量删除或修改.
        return "selected";
     }
    public Map getSelectedIds() ...{
        return selectedIds;
     }
    public List getSelectedDataList() ...{
        return selectedDataList;
     }
}
  相关解决方案