-
1. Re: Seam noob: Categorized h:SelectManyCheckbox with s:selectItems
njrich28 Oct 1, 2010 4:39 PM (in response to carlhecker)Try putting a logging statement in your action.setOptionList() method. You'll probably find that it is called for each category - each time it's called it overwrites the values from the previous category the net effect being that it looks like only the last group works.
That's because when Faces builds the component tree it'll build it with many selectManyCheckboxes linked to the same model value. During the update models phase of the request, faces will traverse the tree and call the action.setOptionList() method for each component.
It's quite a tricky one to solve because you basically need a getter/setter for each list (not possible if the categories are dynamic) or you can store the lists in a map and get a consolidated view later.
In your Action class:
// key is category (presume it's a String) and value is List for each category private Map<String, List> optionMap; public Map<String, List> getOptionMap { return optionMap; } public void setOptionMap(Map<String,List> optionMap) { this.optionMap = optionMap; } public List getConsolidatedList() { List consolidatedList = new ArrayList(); for (List optionList : optionMap.values()) { consolidatedList.addAll(optionList); } return consolidatedList; }
In your page:
<ui:repeat value="#{action.keys}" var="category"> #{category}<br/> <h:selectManyCheckbox value="#{action.optionMap[category]}"> <s:selectItems value="#{action.map[category]}" var="option" label="#{option.description}" /> <s:convertEntity /> </h:selectManyCheckbox> </ui:repeat>
You may need to initialise the optionMap variable somehow but hopefully this should get you on your way.
-
2. Re: Seam noob: Categorized h:SelectManyCheckbox with s:selectItems
carlhecker Oct 5, 2010 8:46 AM (in response to carlhecker)Unfortunately, Seam doesn't seem to like
<h:selectManyCheckbox value="#{action.optionMap[category]}">
My categories aren't dynamic per se, but I wanted to code it so that if the database changed, the site would handle it appropriately. I guess I'm going to have to hardcode this one.
Thanks for the help!