1 Reply Latest reply on Sep 9, 2009 5:20 PM by gus888

    Using Enums with HashMaps and xhtml access

    seamuser111
      Hi, I am having trouble accessing a map from xhtml that contains an Enum type as key. Since Seam can convert enums to strings I assumed going the other direction, String -> Enum conversion would work also, however I am not able to use it. Example code:

        public enum MyType { ONE, TWO }
       
        public Map<MyType, String> getTest() {
          Map<MyType, String> m = new HashMap<MyType, String>();
          m.put(MyType.ONE, "3333");
          return m;
        }`

      On xhtml

        #{obj.test['ONE']}

      This displays null. If I change the key type MyEnum to a String, things work fine. Any suggestions?
        • 1. Re: Using Enums with HashMaps and xhtml access
          gus888
          You need to create a getter method in a bean:

          @name("enums")
          public class Enums() {
             public MyType getONE() {
                return MyType.ONE;
             }
             public MyType getTWO() {
                return MyType.TWO;
             }
          }

          on xhtml
            #{obj.test[enums.ONE]}

          Have a good one!