• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mixing JSTL and JavaScript

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 c:out, 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 ]
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 <c:out> to emit the EL and you should be fine.
 
reply
    Bookmark Topic Watch Topic
  • New Topic