• Post Reply Bookmark Topic Watch Topic
  • New Topic

Weird Expression Langauge Behavior  RSS feed

 
Han You
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a bean with various properties including on that is a char primitive type. When I access that char property in a jsp page using a notion like:
<c ut value="${sessionScope.member.view}"/> it prints out... But if I use....
<c:if test="${sessionScope.member.view == 'Y'}">
</c:if>

an exception occurs that says something to the effect that "Y" is a string, but the sessionScope.member.view is of a different type....I guess my question is, how do you use a char property from a bean in an EL statement in a JSP page... thanks of any help you guys can give me
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not weird at all when you consider that the JSTL has no char type. So both 'Y' and "Y" denote a string with a single character.

Refer to section JSP.2.3.2 in the JSP 2.0 Specification. (If you are writing JSPs and don't have a copy of the Specification handy, you're doing it wrong).
 
Han You
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I don't have the specifications.....BUT yeah...I know what you're talking about with the whole "String" thing, but actually, my question is, do I have to make another "getter" that returns a string instead....or something to that effect.... I mean....is there no way of comparing a char with my value sessionScope.memeber.view using just EL and NOT making a whole new custom tag?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That would probably be the simplest approach.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
char is of course also an integer type so comparing it with the numerical value will also work.
Making another getter that returns a string will make your JSP more easily comprehended at the cost of making your Java class slightly larger, a worthy tradeoff IMO.
 
Han You
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well....thanks for all the help.... I think I'm just going to go with a getter that returns a string. I wish there was a better way though..
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!