I think I've posted this before, either here or in struts-user. At app startup,
process the classes you need and store each in application scope using their
class names as keys (or whatever makes the most sense to you).

    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}"/>

Quoting "Karr, David" <[EMAIL PROTECTED]>:

> > -----Original Message-----
> > From: Rick Reumann [mailto:[EMAIL PROTECTED]
> > 
> > On Tue, 2003-07-22 at 10:54, Karr, David wrote:
> > 
> > > If you have a bunch of constants that you might want to reference,
> you
> > > might consider processing a class with reflection, loading all the
> > > "static final" variables into a hashmap, keyed by the variable name.
> > > The resulting references in your JSP would look almost the same as
> you
> > > were intending.
> > 
> > True, that would work but was wanting to avoid doing that (aka -
> lazy:)
> > Thanks.
> 
> So for every constant value that you want to use, in every JSP page,
> you're going to have a call to the "bind" tag from the unstandard
> library?  This is as opposed to a single block of code in a servlet to
> load the constants into a bean at application startup.

-- 
Kris Schneider <mailto:[EMAIL PROTECTED]>
D.O.Tech       <http://www.dotech.com/>

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

Reply via email to