1

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?

Community
  • 1
  • 1
Arthur Borsboom
  • 323
  • 2
  • 10
  • That doesn't work for `.*`. The correct FQN for an inner class/enum/interface is `com.abc.def.helpers.MyConstants$BusinessObject`. Give it a try and let us know. – BalusC Nov 14 '16 at 08:58
  • This was broken in previous version of WildFly, but it was fixed in WildFly 10.1.0.Final https://issues.jboss.org/browse/WFLY-6939. – James R. Perkins Nov 14 '16 at 20:40
  • @BalusC, Eclipse gives The import cannot be resolved for <%@ page import="com.abc.def.helpers.MyConstants$BusinessObject" %> – Arthur Borsboom Nov 28 '16 at 21:14
  • @JamesR.Perkins, I am using Wildfly 10.1.0 Final. Besides, that is my own ticket, I have reported to the Wildfly team for another issue. :D – Arthur Borsboom Nov 28 '16 at 21:15

0 Answers0