You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Morten Andersen <bl...@blobcom.com> on 2006/03/16 15:28:42 UTC

newbie guestion: JSTL Expression language

I want to use JSTL to check the role of the user (it can be one of many)

I'm new to JSTL so even the simplest things gives me problems:

I've set the role using request.setAttribute("role" , role);

This tag:
<c:out value="${role}"/>

Prints out the role fine

While the following statements are newer true:

          <c:if test="${role}==editor">
                The role is editor
          </c:if>

          <c:if test="${role}=='editor'">
                The role is editor
          </c:if>

Where do I go wrong?

Morten



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: newbie guestion: JSTL Expression language

Posted by Wojciech Ciesielski <wc...@f1.pl>.

Morten Andersen wrote:
> I want to use JSTL to check the role of the user (it can be one of many)
>
> I'm new to JSTL so even the simplest things gives me problems:
>
> I've set the role using request.setAttribute("role" , role);
>
> This tag:
> <c:out value="${role}"/>
>
> Prints out the role fine
>
> While the following statements are newer true:
>
>          <c:if test="${role}==editor">
>                The role is editor
>          </c:if>
>
>          <c:if test="${role}=='editor'">
>                The role is editor
>          </c:if>
>
> Where do I go wrong?
>
test is wrong :-) It should be

test="${role eq 'editor'}

if you want to compare with strings or

test="${role eq editor}

if you have variable "editor" in page/request/session scope with value 
you want to check against

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: newbie guestion: JSTL Expression language

Posted by vijay venkataraman <vi...@ltp.soft.net>.
The text as is from JSP 2.0 Spec

Point 1.
EL expression An element in a JSP page representing an expression to be 
parsed
and evaluated via the JSP Expression Language. Syntactically it is delimited
by the ${ and } characters.

Point 2.
JSP.2.3.5.5 Relational Operators
The relational operators are:
 == and eq
 != and ne
 < and lt
 > and gt
 <= and le
 >= and ge

Point 3
JSP.2.3.5.7 A {==,!=,eq,ne} B
 If A==B, apply operator
 If A is null or B is null return false for == or eq, true for != or ne.
 If A or B is BigDecimal, coerce both A and B to BigDecimal and then:
If operator is == or eq, return A.equals( B )
If  operator is != or ne, return !A.equals( B )
 If A or B is Float or Double coerce both A and B to Double, apply operator
...

Your code
========
<c:if test="${role}==editor">
               The role is editor
         </c:if>

         <c:if test="${role}=='editor'">
               The role is editor
         </c:if>

So from point 1 and point 2

<c:if test="${role=='editor'}">  (See the expression is with in ${} point 1)
               The role is editor
         </c:if>
will work . See Point 2 bulleted points  . == and eq and Point 3 how the 
relational operator is evaluated. You can look for more information in 
the spec.

So
<c:if test="${role=='editor'}">
               The role is editor
         </c:if>
is same as
<c:if test="${role eq 'editor'}">
               The role is editor
         </c:if>

Thanks,
Vijay Venkataraman

Rahul Akolkar wrote:

>On 3/16/06, Morten Andersen <bl...@blobcom.com> wrote:
>  
>
>>I want to use JSTL to check the role of the user (it can be one of many)
>>
>>I'm new to JSTL so even the simplest things gives me problems:
>>
>>I've set the role using request.setAttribute("role" , role);
>>
>>This tag:
>><c:out value="${role}"/>
>>
>>Prints out the role fine
>>
>>While the following statements are newer true:
>>
>>         <c:if test="${role}==editor">
>>    
>>
><snip/>
>
>Expression must be contained in ${ and } in its entirety i.e.
>
>${role eq 'editor'}
>
>
>  
>
>>               The role is editor
>>         </c:if>
>>
>>         <c:if test="${role}=='editor'">
>>    
>>
><snap/>
>
>${role ne 'editor'}
>
>-Rahul
>
>
>  
>
>>               The role is editor
>>         </c:if>
>>
>>Where do I go wrong?
>>
>>Morten
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>  
>


------------------------------DISCLAIMER------------------------------
This message is for the named person's use only. It may contain 
confidential, proprietary or legally privileged information. No
confidentiality or privilege is waived or lost by any mistransmission. 

If you receive this message in error, please immediately delete it and 
all copies of it from your system, destroy any hard copies of it and 
notify the sender. You must not, directly or indirectly, use, disclose, 
distribute, print, or copy any part of this message if you are not the 
intended recipient. 

Lisle Technology Partners Pvt. Ltd. and any of its subsidiaries each 
reserve the right to monitor all e-mail communications through its 
networks. 

Any views expressed in this message are those of the 
individual sender, except where the message states otherwise and the 
sender is authorized to state them to be the views of any such entity.

Re: newbie guestion: JSTL Expression language

Posted by Rahul Akolkar <ra...@gmail.com>.
On 3/16/06, Morten Andersen <bl...@blobcom.com> wrote:
> I want to use JSTL to check the role of the user (it can be one of many)
>
> I'm new to JSTL so even the simplest things gives me problems:
>
> I've set the role using request.setAttribute("role" , role);
>
> This tag:
> <c:out value="${role}"/>
>
> Prints out the role fine
>
> While the following statements are newer true:
>
>          <c:if test="${role}==editor">
<snip/>

Expression must be contained in ${ and } in its entirety i.e.

${role eq 'editor'}


>                The role is editor
>          </c:if>
>
>          <c:if test="${role}=='editor'">
<snap/>

${role ne 'editor'}

-Rahul


>                The role is editor
>          </c:if>
>
> Where do I go wrong?
>
> Morten
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org