Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JSP Interest »

Re: Using constants with EL

Karr, David

2003-09-02

Replies:

> -----Original Message-----
> From: Timo Neumann [mailto:neumannt@(protected)]
>
> Hi all,
>
> I have a class Constants that contains entries like that
>
> public static final String YES = "yes";
>
> I want to access these "constants" in my JSPs with EL, something like:
>
> <html:radio property="partner" value="${Constants.YES}"/>
>
> This way it does not work. How would I do it right?
>
> I've got a workaround that is not very elegant and I would
> like to avoid it:
>
> <c:set var="formRadioYes"><%= Constants.YES %></c:set>
> <html:radio property="partner" value="${formRadioYes}"/>

The EL can reference javabeans properties, and collection and map
entries. That's it (pre-JSP 2.0). It can't reference static variables.

If you have several constants that you want to reference throughout your
view side of the application, create a bean in application scope with
specific properties, or with a map. It's possible to use reflection to
load the "static final" variables from a class into a map.

===========================================================================
To unsubscribe: mailto listserv@(protected)".
For digest: mailto listserv@(protected)".

Some relevant archives, FAQs and Forums on JSPs can be found at:

http://java.sun.com/products/jsp
http://archives.java.sun.com/jsp-interest.html
http://forums.java.sun.com
http://www.jspinsider.com


©2008 junlu.com - Jax Systems, LLC, U.S.A.