vr3w3c9
vr3w3c9

Reputation: 1178

retrieve selected Row data in JSF

I have a JSF page in which, I have created a html table and displaying the row data using ui:repeat. I have a save button where, when I select a particular row, I want the entire row data to be saved. When I try to select the particular row, Im unable to get the row data. ui:repeat does not have a binding attribute to bind it to the backing bean dataTable.

Can you please suggest how to acheive the same. Thanks in Advance

Upvotes: 0

Views: 1304

Answers (2)

Eelke
Eelke

Reputation: 21993

Make sure to hookup the checkboxes to a bean property:

<h:selectBooleanCheckbox id="selection" value="#{listController.checked[item.id]}" />

In your bean you would need:

private Map<Integer, Boolean> checked = new HashMap<Integer, Boolean>();

public Map<Integer, Boolean> getChecked() {
    return checked;
}

Then if you want to know which item(s) were selected you can do:

for (Map.Entry<Integer, Boolean> e : checked.entrySet()) {
    if (e.getValue()) {
        // do something with selected row
     }
 }

Upvotes: 1

Logan
Logan

Reputation: 2505

You can achieve this by passing the current row as parameter in an action that you must call on onchange event of selectBooleanCheckbox using jsf:ajax.

Upvotes: 0

Related Questions