我有rich:dataTable裏面的複選框列表,我想用標題列中的單個複選框同時檢查所有框。JSF-2使用單個複選框選擇/取消選中所有複選框列表
<rich:column id="includeInWHMapping" >
<f:facet name="header">
<h:selectBooleanCheckbox value="#{checkallbox.selectAll}">
<f:ajax actionListener="#{checkallbox.selectAllBox}" render="selectedForWHProcess" />
</h:selectBooleanCheckbox>
</f:facet>
<h:selectBooleanCheckbox id="selectedForWHProcess" value="#{checkallbox.checked[data]}">
<f:ajax actionListener="#{checkallbox.selectAllRows}"/>
</h:selectBooleanCheckbox></rich:column>
守則checkallbox豆:
private Map<StandardStructure, Boolean> checked = new HashMap<StandardStructure, Boolean>();
private boolean selectAll;
public boolean isSelectAll() {
return selectAll;
}
public void setSelectAll(boolean selectAll) {
this.selectAll = selectAll;
}
public Map<StandardStructure, Boolean> getChecked() {
return checked;
}
public void setChecked(Map<StandardStructure, Boolean> checked) {
this.checked = checked;
}
public void selectAllBox(ValueChangeEvent e){
boolean newSelectAll = (Boolean) e.getNewValue();
Iterator<StandardStructure> keys = checked.keySet().iterator();
while(keys.hasNext()){
StandardStructure ss = keys.next();
checked.put(ss, newSelectAll);
}
}
當我檢查了H:的標題欄沒有selectBooleanCheckBox發生。我在這裏錯過了什麼?我是否也必須爲「selectAll」屬性實現Map?
謝謝。
'selectAllBox'是否被觸發,您是否嘗試渲染整個表? –
@EmilSierżęga是的,但它沒有發生在複選框列表上的變化。我沒有渲染整個表格,但複選框列。謝謝回覆! –
你必須渲染整個表格。你不能渲染「一列」。在呈現的HTML中,沒有列是這樣的東西,所以你不想渲染幾個像'tableId:_NUMBER_:selectedForWHProcess'這樣的id。閱讀這兩個主題:http://stackoverflow.com/questions/6706849/how-to-do-a-column-level-render-in-datatable-in-jsf和http://stackoverflow.com/questions/16043218/refer-to-jsf-dynamic-generated-ids-based-ite-index- –