Thanks very much Bill, I was able to make your first suggestion work by
placing the code in the servlet that also creates my "er" object and
"forwards" to my JSP page. It works but I'm fairly certain it's not the
"startup servlet" you were referring to. I searched through apache.org in
the Tomcat section for awhile but didn't find anything that looked like what
you were talking about. I wonder if you would be kind enough to point me in
the right direction/resource where I can find out more about the startup
servlets?
Thanks again for your help!
----- Original Message -----
From: "Bill Siggelkow" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, March 31, 2004 9:32 PM
Subject: Re: Novice question about using "Constants" in "when" tags
> Good question, Jeff. Unfortunately, there is not a direct way of doing
> this. There are generally two approaches:
>
> 1) Store the values of the constants as application context variables
> with the context being initialized through a startup servlet (or via a
> Plugin if you were using Struts)
>
> In the startup servlet you would have:
>
> this.getServletContext().setAttribute("INTRO", new Integer(1));
>
> then your JSTL would look like:
>
> <c:when test="${er.updateStatus == INTRO}">
>
> 2) store a Map of these values in the application context -- something
like:
>
> Map constants = new HashMap();
> constants.put("INTRO", new Integer(1)); //...
> this.getServletContext().setAttribute("Constants", constants);
>
> then your JSTL would look like:
>
> <c:when test="${er.updateStatus == Constants.INTRO}">
>
> Jeff Brewer wrote:
> > I'm new to Java and JSP and Tag Libraries and ran into what is probably
more of a style question than a technical question.
> >
> > I'm using something like this in my JSP page:
> >
> > <c:choose>
> > <c:when test="${er.updateStatus == 1}">
> > <p>message one</p>
> > </c:when>
> > <c:when test="${er.updateStatus == 2}">
> > <p>message two</p>
> > </c:when>
> > <c:when test="${er.updateStatus == 3}">
> > <p>message three</p>
> > </c:when>
> > </c:choose>
> >
> > ... but I wasn't content because a week from now when I come back and
look at this code I'm not going to remember what 1, 2, or 3 means. Then I
got the bright idea of trying to define some "constants" in my "er" class
something like this....
> >
> > public static final int INTRO = 1;
> > public static final int MISSING_EMAIL_ADDRESS = 2;
> > public static final int INVALID_EMAIL_ADDRESS = 3;
> >
> > ... so that I could do something like this...
> >
> > <c:choose>
> > <c:when test="${er.updateStatus == er.INTRO}">
> > <p>message one</p>
> > </c:when>
> > <c:when test="${er.updateStatus == er.MISSING_EMAIL_ADDRESS}">
> > <p>message two</p>
> > </c:when>
> > <c:when test="${er.updateStatus == er.INVALID_EMAIL_ADDRESS}">
> > <p>message three</p>
> > </c:when>
> > </c:choose>
> >
> > ...which I thought would greatly improve the "readability" and
"maintainability" of my JSP page (it's easy to see that message 2 should be
displayed if a Missing Email Address situation exists). Those of you very
familiar with jstl will no doubt recognize that this won't work (something I
discovered through trial and error).
> >
> > Is there some way I can rewrite my expressions that works with these
constants?
> > Have you run into a similar situation and can you suggest a way to make
my crude code a bit more friendly?
> >
> > Thanks in advance,
> > Jeff
>
>
> ---------------------------------------------------------------------
> 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]