Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

[JSTL] How to call a method inside an attribute?  RSS feed

 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having problems with objects and methods in attributes. TagLibraries.pdf did not help.

Always false:

Works:

Encountered '(':

Encountered "true":

Boolean.TRUE evaluates to false because it is called in the tag handler as
Boolean.valueOf("Boolean.TRUE"). So how can i actually put a method call inside the attribute? It should be easy, yet noone can answer this?
[ August 16, 2003: Message edited by: Garrett Smith ]
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSTL used EL (Expression Languge) for this. A full set of available operators in EL is available by downloading Appendix A to "JSTL in Action" by Shawn Bayern
You can simply say
<c:when test='${true}'>
However, it gives you the ability to do more such as testing if the member attribute is set in any scope
<c:when test='${EMPTY member}'>
Or testing for member to be set in the session scope
<c:when test='${EMPTY sessionScope.member}'>
Or seeing if the Attribute "userName" set in any Scope is equal to "Fred"
<c:when test='${userName == "Fred"}'>
It allow == > < >= <= !=
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To use this form of <c:when>,

you have to first say

whereas to use this

you would instead declare

The first is a "run-time expression", while the second uses the Expression Language (EL). These are different things.
If you use the EL, you can't call arbitrary Java methods. You can only (implicitly) call "getter" methods.
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron: thank you. I didn't have c-rt.
I just got c-rt from (included in) http://www.apache.org/dist/jakarta/taglibs/standard/
[list]web.xml:
  • page:


  • Put the tag handlers jarfile in common/lib. Jarfile is jakarta-taglibs-standard-current-src.zip.
  •  
    Garrett Smith
    Ranch Hand
    Posts: 401
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It works.
     
    Charles Hasegawa
    Ranch Hand
    Posts: 117
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Just a footnote - you probably don't want to get used to using "c" as the alias for the c-rt taglibs. It can get confusing pretty quickly, as I expect most people who see a <c:...> tag are expecting that to mean the regular core taglibs.
     
    Ron Newman
    Ranch Hand
    Posts: 1056
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Good point. And if you decide you want to use both forms of the tag library on the same page, you'll have to give them different prefixes.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!