Thang Pham
Thang Pham

Reputation: 38705

selectBooleanCheckbox - How do I know which checkbox am I selecting or deselecting?

I develop something like a shopping cart. I can select multiple items (by clicking on the checkbox next to that item) and add them to a list. How can I know which checkbox I am selecting. If I do this

<h:selectBooleanCheckbox value="#{document.checked}"/>

it only tell me a state of a checkbox is selected or not, but does not tell me which one. Remember the number of items is unknown until runtime since I load them from a datasource, meaning I dont know how many check box there are.

Upvotes: 2

Views: 3665

Answers (1)

Zheileman
Zheileman

Reputation: 2559

You should have a managed bean from which you get and set the booleans for the different checkboxes (different fields with getter and setters for each checkbox value).

Update: take a look at this example, because I think that is what you should be doing. Where the example says "Employee", you take "Article" or whatever your cart items are.

http://www.javabeat.net/tips/43-how-to-use-hselectbooleancheckbox-within-hd.html

Upvotes: 4

Related Questions