This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL c-when ?  RSS feed

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some doubts that JSTL about <%=

This works.


This NOT work
[code]
<c:when test="<%= aList.contains(oneGroup) %>">
[code]

Why ? old version JSTL supports "<%= " ? jsp error always make me frustrated.

Thanks.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We cant use scriplets inside JSTL tags. JSTL is a kind of replacement of scriplets. We use JSTL to get rid of that.
[ November 02, 2005: Message edited by: Adeel Ansari ]
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Are you sure this one works but not the one with expression? This doesn't seem to be value EL syntax!
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to clarify a few things here.

In JSTL1.1/JSP2.0 you CAN use <%= expr %> as well as ${expr} with your JSTL tags.
The responsibility for evaluating the expressions lies with the container.
As far as JSP2.0 is concerned, both methods of using expressions are valid.


In JSTL1.0/JSP1.2 you have to choose whether you use ${expr} or <%= expr %>
That is why they provided the c-rt library - for those who wanted to use <%= expr %> with the JSTL tags.

Looking at your original code: aList.contains(oneGroup)
There is no way to express this using the EL (Expression Language).
There never has been.
The EL can only call basic java bean getters/setters (using reflection)
Methods with parameters are not accessible. Methods which don't start with "get" or "set" are also not accessible.

JSTL1.1 added EL functions, so you could define a function like
public static boolean listContains(list, oneGroup) {
return list.contains(oneGroup);
}
and set it up so you could call it as ${myFn:listContains(aList, oneGroup)}
However that is also a JSP2.0 feature.

Cheers,
evnafets
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent post stefan! I've made an addition to the JSP FAQ on the JSTL based upon it.
[ November 02, 2005: Message edited by: Bear Bibeault ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!