Thanks a lot Luca. Well, it helps a lot because I was starting to feel
that it's me who can not understand this thing, but now I'm relieved.
As to whether it actually solves the problem, I'm not sure, as it seems
that this is still not production yet, so I might have a problem selling
it to my manager, but we'll see :)

Thanks again :)

-----Original Message-----
From: Luca Passani [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 22, 2006 2:23 PM
To: Tag Libraries Users List
Subject: Re: Mixing EL and Java expressions


Since Martin Cooper is probably still sleeping in his time zone, here is

how I fixed the constants problem thanks to him once.
You need something called the unstandard tag-lib by Apache:

http://jakarta.apache.org/taglibs/sandbox/doc/unstandard-doc/index.html

once you have that, you can do something like (SomeClassOrInterface is 
where your constants are defined):

 <un:useConstants var="ct"
className="com.mycom.app.SomeClassOrInterface" />
   <c:forEach var="item"  items="${list}">
    <c:choose>
     <c:when test="${item.type == ct.EMPLOYEE}">
       bla bla relevant to employee
     </c:when>

Let me know if this helps

Luca

Tarek Nabil wrote:

>Hi everyone,
>
> 
>
>I'm moving from the Struts tag libraries to JSTL and I'm having a bit
of
>a hard time. Things don't work as I thought they would. For example,
I'm
>not able to use constants defined in classes for comparison, which is
>something I used to do easily with Struts tags. Here's an example; I
>want to do something if the display parameter equals the constant
>DISPLAY_BY_SERVICE defined in some class and do something else if it
has
>the value DISPLAY_BY_BU. First, I tried this
>
> 
>
>    <c:choose>
>
>      <c:when test="${param.display == <%=
>MainPageAction.DISPLAY_BY_SERVICE %>}">
>
>            By Service
>
>      </c:when>
>
>      <c:when test="${param.display == <%= MainPageAction.DISPLAY_BY_BU
>%>}">
>
>            By BU
>
>      </c:when>
>
>    </c:choose>
>
> 
>
>That didn't even compile, so I learned my first lesson: I can not use
>Java expression inside EL expressions. So, I tried this
>
> 
>
>    <c:set var="displayParam" value="${param.display}"/>
>
>    <c:choose>
>
>      <c:when test="<%=
>MainPageAction.DISPLAY_BY_SERVICE.equals(displayParam) %>">
>
>      <%= MainPageAction.DISPLAY_BY_SERVICE %>
>
>      </c:when>
>
>      <c:when test="<%=
>MainPageAction.DISPLAY_BY_BU.equals(displayParam) %>">
>
>      <%= MainPageAction.DISPLAY_BY_BU %>
>
>      </c:when>
>
>    </c:choose>
>
> 
>
>That didn't compile either, so now I know that unlike <bean:define>,
><c:set> doesn't define a scripting variable, but only a page scope
>variable. So, I tried this
>
> 
>
>    <c:choose>
>
>      <c:when test="${param.display} == <%=
>MainPageAction.DISPLAY_BY_SERVICE %>">
>
>            By Service
>
>      </c:when>
>
>      <c:when test="${param.display} == <%=
MainPageAction.DISPLAY_BY_BU
>%>">
>
>            By BU
>
>      </c:when>
>
>      <c:otherwise>Otherwise</c:otherwise>
>
>    </c:choose>
>
> 
>
>Now, that compiled. But it didn't work!!! So, now I know that the value
>of test should either be the String true or an expression that
evaluates
>to true, so mixing expressions won't work this way.
>
> 
>
>Now, this is what worked, and it's not elegant at all.
>
> 
>
>    <c:set var="DISPLAY_BY_SERVICE" value="<%=
>MainPageAction.DISPLAY_BY_SERVICE %>"/> 
>
>    <c:set var="DISPLAY_BY_BU" value="<%= MainPageAction.DISPLAY_BY_BU
>%>"/>
>
>    <c:choose>
>
>      <c:when test="${param.display == DISPLAY_BY_SERVICE}">
>
>            By Service
>
>      </c:when>
>
>      <c:when test="${param.display == DISPLAY_BY_BU}">
>
>            By BU
>
>      </c:when>
>
>      <c:otherwise>Otherwise</c:otherwise>
>
>    </c:choose>
>
> 
>
>What if I had 5 constants, do I have to re-define the 5 constants as
>vars using <c:set>? Either I'm missing something or JSTL is really not
>what I thought it was. I mean, maybe I should go back to the bean and
>logic libraries from Struts, they used to really do the job for me.
>
> 
>
>Could someone please guide me on this issue?
>
> 
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
********************************************DISCLAIMER********************************************
This email and any files transmitted with it are confidential and contain 
privileged or copyright 
information. If you are not the intended recipient you must not copy, 
distribute or use this email
or the information contained in it for any purpose other than to notify us of 
the receipt thereof.
If you have received this message in error, please notify the sender 
immediately, and delete this
email from your system.

Please note that e-mails are susceptible to change.The sender shall not be 
liable for the improper
or incomplete transmission of the information contained in this 
communication,nor for any delay in
its receipt or damage to your system.The sender does not guarantee that this 
material is free from
viruses or any other defects although due care has been taken to minimise the 
risk.
**************************************************************************************************

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to