> -----Original Message-----
> From: news [mailto:[EMAIL PROTECTED] Behalf Of Bill Siggelkow
> Sent: Wednesday, March 31, 2004 6:32 PM
> To: [EMAIL PROTECTED]
> 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}">
3) Use the 'bind' tag from the Jakarta Unstandard Taglib to bind the Java
constants to scoped attributes. For example:
<un:bind var="INTRO" type="com.foo.YourClass" field="INTRO"/>
Note, however, that Unstandard is still in the sandbox, and therefore
unreleased and subject to change.
--
Martin Cooper
>
> 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]