There was a thread asking exactly the same question earlier in the week. Have a look in the archives.
Paul > -----Original Message----- > From: Woodchuck [mailto:[EMAIL PROTECTED] > Sent: Friday, August 27, 2004 5:06 PM > To: Struts Users Mailing List > Subject: Re: Struts or JSTL equivalent for this? > > > 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] > ********************************************************************** Axios Email Confidentiality Footer Privileged/Confidential Information may be contained in this message. If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone. In such case, you should destroy this message, and notify us immediately. If you or your employer does not consent to Internet email messages of this kind, please advise us immediately. Opinions, conclusions and other information expressed in this message are not given or endorsed by my Company or employer unless otherwise indicated by an authorised representative independent of this message. WARNING: While Axios Systems Ltd takes steps to prevent computer viruses from being transmitted via electronic mail attachments we cannot guarantee that attachments do not contain computer virus code. You are therefore strongly advised to undertake anti virus checks prior to accessing the attachment to this electronic mail. Axios Systems Ltd grants no warranties regarding performance use or quality of any attachment and undertakes no liability for loss or damage howsoever caused. ********************************************************************** --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]