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

Reply via email to