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]



Reply via email to