3

Possible Duplicate:
Reference interface constant from EL

So I have a JSP that currently has no scriptlets in it, i.e. there are no occurrences of "<%" (with the exception of "<%@") and instead multiple occurrences of "${javaVar}", which is EL.

I now need to add something like this:

<security:hasPermissionTo functionKey="<%= FunctionKeyConstants.CREATE %>" ... 

But I don't want to break the convention of this JSP. Can I do this using EL? Or any other suggestions?

Community
  • 1
  • 1
Ed .
  • 6,373
  • 8
  • 62
  • 82

1 Answers1

4

Java Class

public class FunctionKeyConstants{
        public static final String NAME="Jigar";
        public String getNAME(){//NOTE THAT ITS NOT STATIC
             return NAME;
        }
}

JSP

<jsp:useBean id="cons" class="com.example.FunctionKeyConstants" scope="session"/>

then

${cons.NAME}
jmj
  • 237,923
  • 42
  • 401
  • 438
  • 3
    This doesn't work. First, you would need a getter for the constant or you can't get at it using EL, since EL uses the JavaBean notation. Second, useBean must be able to instantiate the bean, which means that even with getters you can't use this for static utility classes or enums. – Steven Benitez Nov 24 '10 at 18:18
  • @Steven Benitez - `jsp:useBean` would be able to instantiate `FunctionKeyConstants` as its written, since there is a default (public, no-arg) constructor. But the EL express would fail without a getter, as you say. – erickson Nov 24 '10 at 18:36
  • 1
    @erickson - Yeah, I get that the instantiation would work with the provided example (though fail later, as you indicated), but it would not work as a general strategy. – Steven Benitez Nov 24 '10 at 18:40
  • @Steven Benitez ,@erickson Yeah missed the getters to add here :) – jmj Nov 24 '10 at 18:48