6 Replies Latest reply on Jan 4, 2017 3:52 PM by James Perkins

    Why does Expression Language with an inner enum not return a value?

    Arthur Borsboom Newbie

      I am using Wildfly 10.1 which has EL 3.0 support and thus support for constants in EL (How to reference constants in EL?). I have a class with an inner enum.

       

      package com.abc.def.helpers;
      
      import java.util.HashMap;
      import java.util.Map;
      
      public class MyConstants {
           public enum BusinessObject {
                CALENDAR ("Calendar"),
                PROJECT ("Project");
      
                private final String friendlyName;
                private static final Map<String, BusinessObject> friendlyNameToEnum = new HashMap<>();
      
                private BusinessObject(String value) {
                     friendlyName = value;
                }
      
                static {
                     for (BusinessObject businessObject : values()) {
                          friendlyNameToEnum.put(businessObject.toString(), businessObject);
                     }
                }
      
                @Override
                public String toString() {
                     return friendlyName;
                }
      
                public static BusinessObject fromString(String friendlyName) {
                     return friendlyNameToEnum.get(friendlyName);
                }
           }
      }
      

       

      I have a JSP file with the following.

       

      <%@ page import="com.abc.def.helpers.MyConstants.*" %>

      Constant scriplet: [<%= BusinessObject.CALENDAR.toString() %>]<br>

      Constant EL: [${BusinessObject.CALENDAR}]<br>

       

      The result is:

      Constant scriplet: [Calendar]

      Constant EL: []

       

      How can I retrieve the value by EL?