You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Zack Chandler <za...@drainpatrol.com> on 2005/10/17 02:33:10 UTC

Type coersion question. Comparing char equality

Hi.  Is there a way to not have the default type coercion (converts to Long)
happen when comparing chars.  I simply want to test for char equality in a
JSP.  See example below.  Thanks.


// Controller code
char tChar = 't';
request.setAttribute("tChar", tChar);

// Now in JSP enter this fragment
<!-- JSP Frag -->
Prints t
${tChar}

Crashes
<c:if test="${tChar == 't'}">
  inside	
</c:if>
<!-- End Frag -->

It crashes with this error:

javax.servlet.jsp.el.ELException: An exception occured trying to convert
String
"t" to type "java.lang.Long"



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


RE: Type coersion question. Comparing char equality

Posted by Zack Chandler <za...@drainpatrol.com>.
Thanks for the help on this.  I really appreciate it.  

-- Zack

-----Original Message-----
From: Rahul Akolkar [mailto:rahul.akolkar@gmail.com] 
Sent: Sunday, October 16, 2005 5:51 PM
To: Tag Libraries Users List
Subject: Re: Type coersion question. Comparing char equality

On 10/16/05, Zack Chandler <za...@drainpatrol.com> wrote:
> Hi.  Is there a way to not have the default type coercion (converts to
Long)
> happen when comparing chars.  I simply want to test for char equality in a
> JSP.  See example below.  Thanks.
<snip/>

I now realize I should have suggested a solution in the comment to
your issue ticket in bugzilla.

EL has no notion of char, it only knows about "StringLiterals", which
is what 't' becomes in:

<c:if test="${tChar == 't'}">

If your immediate interest is evaluating this equality condition, I'd
use a String in the request.setAttribute, one that consists of one
character "tChar".

Let me know if you have other questions.

-Rahul

>
>
> // Controller code
> char tChar = 't';
> request.setAttribute("tChar", tChar);
>
> // Now in JSP enter this fragment
> <!-- JSP Frag -->
> Prints t
> ${tChar}
>
> Crashes
> <c:if test="${tChar == 't'}">
>  inside
> </c:if>
> <!-- End Frag -->
>
> It crashes with this error:
>
> javax.servlet.jsp.el.ELException: An exception occured trying to convert
> String
> "t" to type "java.lang.Long"
>
>

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


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


Re: Type coersion question. Comparing char equality

Posted by Rahul Akolkar <ra...@gmail.com>.
On 10/16/05, Zack Chandler <za...@drainpatrol.com> wrote:
> Hi.  Is there a way to not have the default type coercion (converts to Long)
> happen when comparing chars.  I simply want to test for char equality in a
> JSP.  See example below.  Thanks.
<snip/>

I now realize I should have suggested a solution in the comment to
your issue ticket in bugzilla.

EL has no notion of char, it only knows about "StringLiterals", which
is what 't' becomes in:

<c:if test="${tChar == 't'}">

If your immediate interest is evaluating this equality condition, I'd
use a String in the request.setAttribute, one that consists of one
character "tChar".

Let me know if you have other questions.

-Rahul

>
>
> // Controller code
> char tChar = 't';
> request.setAttribute("tChar", tChar);
>
> // Now in JSP enter this fragment
> <!-- JSP Frag -->
> Prints t
> ${tChar}
>
> Crashes
> <c:if test="${tChar == 't'}">
>  inside
> </c:if>
> <!-- End Frag -->
>
> It crashes with this error:
>
> javax.servlet.jsp.el.ELException: An exception occured trying to convert
> String
> "t" to type "java.lang.Long"
>
>

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