Easy way:
--------
You can always use the "unstandard" tags.  Works great for me:

<un:bind type="com.company.project.Const" field="SOME_CONST" var="yourVar"/>
<c:if test="${$yourVar == 'some value'}">
 <c:out value="${yourVar}"/>
</c:if>


Not so easy way:
---------------
(by Kris Schneider on taglib-users)

Put something like this in a startup servlet or a plug-in:

    public static Map getConstantFieldsAsMap(Class cls)
      throws IllegalAccessException {
        Field[] allFields = cls.getDeclaredFields();
        int numFields = allFields.length;
        Map propMap = new HashMap(numFields);
        for (int i = 0; i < numFields; i++) {
            Field f = allFields[i];
            int mods = f.getModifiers();
            if (Modifier.isPublic(mods) &&
                Modifier.isStatic(mods) &&
                Modifier.isFinal(mods)) {
                String name = f.getName();
                Object value = f.get(null);
                propMap.put(name, value);
            }
        }
        return Collections.unmodifiableMap(propMap);
    }

In JSP:

<c:set var="responseMap"

value="${applicationScope['javax.servlet.http.HttpServletResponse']}"/>
SC_NOT_FOUND: <c:out value="${responseMap.SC_NOT_FOUND}"/>


Search the archives on taglib-user for more details.


--
James Mitchell
Software Developer/Struts Evangelist
http://www.struts-atlanta.org
678-910-8017
AIM:jmitchtx


----- Original Message ----- 
From: "Mike Whittaker" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Friday, August 01, 2003 7:46 AM
Subject: RE: simple - import


>
> >
> ><c:set var="yourVar"><%= Const.MY_CONST %></c:set>
> >
>
> Good grief is this the only way?
>
> a/ isn't the aim to do without scriptlets/expressions?
>
> b/ all the data exists, server side in the app, why do I have to jump
> through hoops, copying CONSTANTS over to another variable???
>
> :-(
>
> --
> Mike W
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to