1

in an WebApp (JSF 2.1 with Primefaces) I want to use a HashMap to fill a SelectManyMenu (with Checkboxes). The HashMap is initialized with some Values and the key set to false. When the User selects the Checkboxes I want the Key to be set to true.

Is this possible or do I have to think about another solution?

Thanks in advance, Tim

  • Can't you create list with objects? Each object can contain two required fields. – pepuch Dec 03 '13 at 09:54
  • possible duplicate of [How to display hashmap in JSF using selectonemenu?](http://stackoverflow.com/questions/11484126/how-to-display-hashmap-in-jsf-using-selectonemenu) – Johny T Koshy Dec 03 '13 at 11:01
  • Hi Johny, the linked article describes a `Map` with the label as key and the concrete object as value. Tim wants to have a `Map` with the concrete object as key and the selection as value. – L-Ray Dec 03 '13 at 11:36
  • why do not use manymenu just like in showcase? http://www.primefaces.org/showcase/ui/selectManyMenu.jsf – erencan Dec 03 '13 at 14:50

1 Answers1

1

I would strongly recommend

  • provide a List of the possible items and
  • expect a list of selected items.

When you really need a HashMap on server-side, use a valueChangeListener to sync these lists into your Map. in meta-code the JSF might look like

<h:selectManyMenu value="#{bean.listOfSelectedItems}">
   <f:selectItems value="#{bean.listOfPossibleItems}" 
        var="item" itemLabel="#{item.name}" />
</h:selectManyMenu>

Am not sure, but guess the getter/setter for listOfSelectedItems will expect Objects.

Hope it helps...

L-Ray
  • 1,637
  • 1
  • 16
  • 29