Lukas Novicky
Lukas Novicky

Reputation: 952

jsf datatable with selectbooleancheckbox

I have following code: JSF PAGE

<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>

and BEAN code:

@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;
    }

problem is when I click button, selected values are not submitted. I was reading this article: How to use <h:selectBooleanCheckbox> in <h:dataTable> to select multiple rows?

did everything the same way, but it does not work.

Upvotes: 0

Views: 5290

Answers (1)

Zaw Than oo
Zaw Than oo

Reputation: 9935

Update the datatable when the Checkbox is selected.

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

Upvotes: 1

Related Questions