2014-03-07 35 views
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?

做了一切都一樣的方式,但它不起作用。

回答

0

選擇Checkbox時更新數據表。

<h:selectBooleanCheckbox value="#{bean.checked[app.id]}"> 
    <f:ajax event="valueChange" render=":YOUR_FORM_ID:YOUR_TABLE_ID"/> 
</h:selectBooleanCheckbox> 
+0

好吧...它的工作。謝謝。你能解釋爲什麼我的代碼不工作? –

+0

我很抱歉我的解釋。嘗試學習'JSF請求處理生命週期'。 – CycDemo

相關問題