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

Mixing JSTL and JavaScript  RSS feed

 
Mike Himstead
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
H,

first some code:


The snippet is part of a search page I'm working on, it's purpose is tp display results with each result containing one or two links or buttons (let's stay with buttons for now). The buttons will need to return the specific results database ID to the server so the server can see which result is meant. The form containing the results has two special fields to identify which button was clicked on, but I have to put the ID into the field; this is done by the onclick JavaScript function. I need to pass in the ID to the JS function, of course. Problem is that the server can't resolve/evaluate ${protVBean.protocolId} within the onlick attribute, it passes this as a string literal to the function. I tried several different approaches with c:set and cut, but they all didn't work for varous reasons. Any suggestions are very welcome.

By the way, the solution has to work in Websphere 6.0, JSTL 1.0 and a web application conforming to the 2.3. I did the above in a Tomcat 5.0.28 and a 2.4 application where it worked without a flaw, but the Websphere / 2.3 combo gives me a fuzz.
[BPSouther: Narrowed the code a bit to make the rest more readable]
[ October 22, 2007: Message edited by: Ben Souther ]
 
Tarun Yadav
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at these:

[1] http://faq.javaranch.com/java/ElOrJstlNotWorkingAsExpected
[2] http://faq.javaranch.com/java/SetupJstlForJsp2
[3] http://faq.javaranch.com/java/JstlTagLibDefinitions
[4] http://faq.javaranch.com/java/ServletsWebXml

JSTL 1.0 was meant for containers supporting Servlet spec 2.3 when the container didn't support EL; that was only provided by the JSTL rt library. There were two versions of the libraries available.

In your case, it work with Tomcat probably because the container itself handles evaluation of the EL. In the other case, you're probably using the non-rt library so the EL strings remain as they are, unevaluated.

You'll probably have to change your URI for the taglib directive; take a look at the links to get an idea of what they should be.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JSP 1.2 and JSTL 2.0 you cannot use the EL in template text. You can only use the EL within the attributes of JSTL tags.

Use <cut> to emit the EL and you should be fine.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!