0
JSF的DataTable我有以下代碼: JSF頁面與selectbooleancheckbox
<h:dataTablevalue="#{bean.records}" var="app">
<h:column>
<h:selectBooleanCheckbox value="#{bean.checked[app.id]}"/>
<f:facet name="footer">
<h:commandButton value="submit" action="#{bean.submitPublic}"/>
</f:facet>
</h:column>
和BEAN代碼:
@SessionScoped
public class bean
private Map<Long, Boolean> checked = new HashMap<Long, Boolean>();
private List<Application> checkedItems = new ArrayList<Application>();
public void submit() {
for (Application app : getRecords()) {
if (checked.get(app.getId())) {
checkedItems.add(app);
}
}
checked.clear();
//here logic for selected apps
}
public Map<Long, Boolean> getChecked() {
return checked;
}
public void setChecked(Map<Long, Boolean> checked) {
this.checked = checked;
}
問題是,當我點擊按鈕,選擇的值不會被提交。 我正在讀這篇文章: How to use <h:selectBooleanCheckbox> in <h:dataTable> to select multiple rows?
做了一切都一樣的方式,但它不起作用。
好吧...它的工作。謝謝。你能解釋爲什麼我的代碼不工作? –
我很抱歉我的解釋。嘗試學習'JSF請求處理生命週期'。 – CycDemo