javaserverfaces
  1. javaserverfaces
  2. JAVASERVERFACES-1808

f:selectItems with Map<K,V> should use K as option value and display V as option label

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.0.3
    • Fix Version/s: unscheduled
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      1,808

      Description

      The f:selectItems has an undocumented feature. It supports a Map<K, V> as
      well. This is very handy. I'd intuitively expect it to use the map keys as
      option values because they are supposed to be unique. Map values are then to be
      used as option labels. However, the f:selectItems uses it the other way round:
      map keys are option labels and map values (which aren't necessarily unique) are
      used as option values.

      Can this be done the other way round (map keys becomes option values and map
      values become option labels) and be more explicitly documented? I can't seem to
      find any pointers about this in f:selectItems tlddoc nor the JSF 2.0 specification.

        Activity

        Hide
        balusc added a comment -

        By the way, the following workaround attempt doesn't work, but it can't be
        marked as a bug since it's apparently undocumented.

        <f:selectItems value="#

        {bean.map}

        " var="entry"
        itemValue="#

        {entry.key}

        " itemLabel="#

        {entry.value}

        " />

        Show
        balusc added a comment - By the way, the following workaround attempt doesn't work, but it can't be marked as a bug since it's apparently undocumented. <f:selectItems value="# {bean.map} " var="entry" itemValue="# {entry.key} " itemLabel="# {entry.value} " />
        Hide
        Ed Burns added a comment -

        Regarding the Map support being undocumented, the JavaDoc for
        javax.faces.component.UISelectItems does state that Map is supported.

        Unfortunately, doing what you suggest would be a disruptive and backwards
        incompatible change. Unfortunately, the usual trick of just introducing a
        context-param is overkill and entirely too specific.

        I suppose you could wrap the real map in a Map imelementation that swaps key and
        value, right?

        In any case, I have to mark this as WONTFIX.

        Show
        Ed Burns added a comment - Regarding the Map support being undocumented, the JavaDoc for javax.faces.component.UISelectItems does state that Map is supported. Unfortunately, doing what you suggest would be a disruptive and backwards incompatible change. Unfortunately, the usual trick of just introducing a context-param is overkill and entirely too specific. I suppose you could wrap the real map in a Map imelementation that swaps key and value, right? In any case, I have to mark this as WONTFIX.
        Hide
        Manfred Riem added a comment -

        Closing resolved issue out

        Show
        Manfred Riem added a comment - Closing resolved issue out

          People

          • Assignee:
            Ed Burns
            Reporter:
            balusc
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: