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 n开发者_运维百科ext 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.
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
精彩评论