I've had such a case before and solved it using a custom tag (sorry, old project, 
don't have sources anymore)

It looked like this :

<my:static var="admin" class="com.foo.Enum" member="ADMIN"/>

it used reflexion API to get Class object and read member. it used a Map to cache 
values for perfs. Something like this
:

    String key = className + "+" + member;
    Object value = cache.get(key);
    if (value == null)
    {
        Class clazz = Class.forName(className);
        Field field = clazz.getField(member)
        Object value = field.get(clazz);
        map.put(key, value);
    }
    return value;


it may be used next like this :

<my:static var="admin" class="com.foo.Enum" member="ADMIN"/>
<c:when test="${role.roleChar eq admin.roleChar}">

Not sure, but <c:when test="${role eq admin}"> may work if JSTL uses equals() for 
evaluation (?)

Nico.



> I've asked this before on the list and didn't get a neat answer. I've
> resorted to using c:set & scriptlets to extract the value from the static
> and store it in a scoped attribute for use with JSTL.
>
> Paul
>
>
> > -----Original Message-----
> > From: Janne Mattila [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, August 26, 2004 1:42 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: [OT(?)] Comparing against a typesafe enum in JSTL
> >
> >
> > Um, no, doesn't work:
> >
> > [ServletException in:/pages/cd/content/common/menu.jsp]
> > jsp.error.tlv.invalid.page
> >
> > 10: tag = 'when' / attribute = 'test': An error occurred
> > while parsing
> > custom action attribute "test" with value
> > "${sessionScope.role.roleChar.equals(cd.business.Role.ADMIN)}"
> > : Encountered
> > "(", expected one of ["}", ".", ">", "gt", "<", "lt", "==",
> > "eq", "<=",
> > "le", ">=", "ge", "!=", "ne", "[", "+", "-", "*", "/", "div",
> > "%", "mod",
> > "and", "&&", "or", "||"]
> >
> > besides, wouldn't that be comparing a char (besides, calling
> > char's equals()
> > method, which does not exist sice char is a primitive) to a Role?
> >
> > Anyway, thanks for the suggestion, other ideas?
> >
> >
> > >From: Can Zheng <[EMAIL PROTECTED]>
> > >Reply-To: Can Zheng <[EMAIL PROTECTED]>
> > >To: Struts Users Mailing List <[EMAIL PROTECTED]>
> > >Subject: Re: [OT(?)] Comparing against a typesafe enum in JSTL
> > >Date: Thu, 26 Aug 2004 20:32:27 +0800
> > >
> > >Hi,
> > >you can use
> > >
> > ><c:when
> > >test="${sessionScope.role.roleChar.equals(cd.business.Role.ADMIN)}">
> > >...
> > >
> > >
> > >
> > >
> > >On Thu, 26 Aug 2004 12:09:56 +0000, Janne Mattila
> > ><[EMAIL PROTECTED]> wrote:
> > > > First, apologies for a slightly OT question; this is more
> > about JSTL and
> > > > less about Struts.
> > > >
> > > > Let's say I have a "Role" object in session. It is a
> > typesafe enum, with
> > > > values Role.ADMIN and Role.USER. How can I compare the
> > object in session
> > > > against those values, using JSTL? I can't figure out how
> > to refer to
> > > > typesafe enum objects using the JSTL notation. And I
> > don't really want
> > >to
> > > > change the enum class into a JavaBean.
> > > >
> > > > Role:
> > > >
> > > > public class Role {
> > > >        private char roleChar;
> > > >
> > > >        public static final Role USER = new Role('u');
> > > >        public static final Role ADMIN = new Role('a');
> > > >
> > > >        private Role(char roleChar) {
> > > >                this.roleChar = roleChar;
> > > >        }
> > > >
> > > >        char getRoleChar() {
> > > >                return roleChar;
> > > >        }
> > > >
> > > >        public boolean equals(Object obj) {
> > > >                Role r2 = (Role) obj;
> > > >                if (r2 == null) {
> > > >                        return false;
> > > >                }
> > > >                return r2.getRoleChar() == roleChar;
> > > >        }
> > > > }
> > > >
> > > > My attempt to use it in JSP page:
> > > >
> > > > <c:choose>
> > > > <c:when test="${sessionScope.role == cd.business.Role.ADMIN}">
> > > >  Hello Admin
> > > > </c:when>
> > > > <c:otherwise>
> > > >  Hello User
> > > > </c:otherwise>
> > > > </c:choose>
> > > >
> > > > does not work.
> > > >
> > > > (this special case could possibly be handled using
> > container managed
> > > > authorization and it's roles etc....but it's not really
> > the point here)
> > > >
> > > > _________________________________________________________________
> > > > MSN 8 with e-mail virus protection service: 2 months FREE*
> > > > http://join.msn.com/?page=features/virus
> > > >
> > > >
> > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > >
> > > >
> > >
> > >
> > >--
> > >Best regards,
> > >
> > >Can Zheng
> > >
> > >---------------------------------------------------------------------
> > >To unsubscribe, e-mail: [EMAIL PROTECTED]
> > >For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> >
> > _________________________________________________________________
> > Help STOP SPAM with the new MSN 8 and get 2 months FREE*
> > http://join.msn.com/?page=features/junkmail
> >
> >
> > ---------------------------------------------------------------------
> > 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]



Our name has changed.  Please update your address book to the following format: 
"[EMAIL PROTECTED]".

This message contains information that may be privileged or confidential and is the 
property of the Capgemini Group. It is intended only for the person to whom it is 
addressed. If you are not the intended recipient,  you are not authorized to read, 
print, retain, copy, disseminate,  distribute, or use this message or any part 
thereof. If you receive this  message in error, please notify the sender immediately 
and delete all  copies of this message.


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

Reply via email to