0

I have the following JSF construct:

    <c:set var="myVar" value="#{myBean.getMyMap()}" scope="request" />
    <h:form>
    <p>
        <h:outputText value="Output1: " />
        <h:selectOneMenu value="#{myMappingsBean.data.attribute1}" binding="#{input1}" required="true">
            <f:selectItems var="entry" value="#{myVar}"/>
            <p:ajax update="myDropdown"/>
        </h:selectOneMenu>
    </p>
    <p>
        <h:outputText value="Output2: " />
        <h:selectOneMenu id="myDropdown" value="#{myMappingsBean.data.attribute2}" binding="#{input2}" required="true" converter="javax.faces.Double">
            <f:selectItems var="entry" value="#{myVar.get(input1.value)}"/>
        </h:selectOneMenu>
    </p>
    </h:form>

Behind myVar is a map defined like that: Map<String, Collection<Double>>

The first dropdown menu shows a list of all the keys of that map (like desired), but the value behind that is the collection of values. Here the HTML output of one option of that dropdown:

<option value="[1.0, 2.0]">SomeString</option>

My second dropdown should list the collection of double values stored in the map behind the key, that is selected by the first menu. The problem now is, when I use value="#{myVar.get(input1.value)}" the value I get from .value is the collection and not the string/key of the map. So I never get the desired result. How can I get the string/key behind the binded object input1? Is there something like input1.name or .toString? Is somewhere a documentary for this?

kinglite
  • 339
  • 3
  • 20
  • 1
    Please attache the bean sources. Access bean fields trough properties (getter/setter methods) in EL expressions : `... value="#{myBean.myMap}"` – The Bitman May 03 '17 at 16:55
  • There is no attribute myMap in the bean. There is only the method getMyMap() that returns the said map. It's also not going to be changed by the page, so I guess no setter is needed. All the other setter and getter of `.data` just set or return the variable. My problem lies within the object `input1`. With `.value` I get the value, but I also need the string that is hopefully also stored there. – kinglite May 04 '17 at 07:08

1 Answers1

0

Ok, I solved it by applying the solution from here. The first drop down has to be edited to the following:

    <p>
        <h:outputText value="Output1: " />
        <h:selectOneMenu value="#{myMappingsBean.data.attribute1}" binding="#{input1}" required="true">
            <f:selectItems var="entry" value="#{myVar.entrySet()}" itemValue="#{entry.key}" itemLabel="#{entry.key}"/>
        </h:selectOneMenu>
    </p>

As you can see, the entry set is created from the map and from that you use the key as value and label. And with that the value behind input1.value now is not the collection of doubles but the key of the map.

Community
  • 1
  • 1
kinglite
  • 339
  • 3
  • 20