lol! not what i was expecting, but very interesting! :) before i use this suggestion, would anyone else like to challenge this solution with a *more elegant* solution? ;)
and without making getters and setters!! woodchuck --- Rick Reumann <[EMAIL PROTECTED]> wrote: > Woodchuck wrote: > > > how can i do the following the non-scriptlet way on my jsp page? > > > > <%@ page import="MyPackage.Constants"%> > > > > <%= Constants.BUTTON__KEY %> > > > > > > is there an elegant Struts or JSTL equivalent for the above? > > Thankfully Kris Schneider demonstrated a good way to handle this... > > In your Constants class add a method similar to this: > > public static Map getConstantsMap() { > Map propMap = null; > try { > Field[] allFields = Constants.class.getDeclaredFields(); > int numFields = allFields.length; > 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); > } > } > } catch(IllegalAccessException ie) { > log.error("Problem loading getConstantsMap " + ie); > } > > return Collections.unmodifiableMap(propMap); > } > > > Then, I have a Servlet that runs on applications startup (such as a > ServletContextListener) that will load the constants map into > application scope: > > ServletContext context = contextEvent.getServletContext(); > try {... > context.setAttribute("CONSTANTS", Constants.getConstantsMap()); > > Now anywhere in your JSPs you can just use the Map > > ${CONSTANTS.SOME_CONSTANT} > > > -- > Rick > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > _______________________________ Do you Yahoo!? Win 1 of 4,000 free domain names from Yahoo! Enter now. http://promotions.yahoo.com/goldrush --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]