0

Showing a JSF page, with a selectOneMenu component that lists every item of a enum class. This Enum class corresponds to cities.

Problem is that I want to show one field that says "All Cities", as I'm showing a *List<City>* I can't add the "All Cities" value because that would be a String.

So actual items being showed in the SelectOneMenu is e.g.:

NYC, San Francisco, Rome, Paris

And the desired output would be:

All Cities, NYC, San Francisco, Rome Paris

Code Example:

Enum:

 public enum City {

    ALL, NYC, SANFRANCISCO,...;

    }

JSF Page code snippet:

<h:selectOneMenu id="citiesmenu" value="#{enumBeanStatus.selectedCity}">
<f:selectItems value="#{enumBean.cities}"/>
</h:selectOneMenu>
jacktrades
  • 7,224
  • 13
  • 56
  • 83
  • 1
    You could add the `All Cities` value in your enum. If that's not an option, then you could add `` before the ``. – Luiggi Mendoza Jan 22 '13 at 15:09
  • How can I add *All Cities* to my enum, if *All Cities* is not a City :) I would think the second option would be the actual answer :) – jacktrades Jan 22 '13 at 15:11
  • 3
    I don't know how you're setting up your enum, but just add `ALL_CITIES` as part as the enum. It could have a different value from the other cities like 0 or another default value, it's just a *trick*. – Luiggi Mendoza Jan 22 '13 at 15:13
  • @kauedg what kind of code would be useful to solve this problem? It's a logical problem, not a code error. – Luiggi Mendoza Jan 22 '13 at 15:22
  • @LuiggiMendoza add the second comment to the answer so I can select it – jacktrades Jan 22 '13 at 15:22

1 Answers1

1

I don't know how you're setting up your enum, but just add an ALL_CITIES as part as the City enum. It could have a different value from the other cities like 0 or another default value, it's just a trick. The way how you process the different values is what defines if is a general or a specific one.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332