It's not a secret anymore!*
The moose likes Struts and the fly likes Problem using jstl in javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem using jstl in javascript" Watch "Problem using jstl in javascript" New topic
Author

Problem using jstl in javascript

Bradusca Luisa
Greenhorn

Joined: Oct 28, 2009
Posts: 6
Hi all, in my jsp page I have:


And in my javascript function:


And it doesn't takes the index in ${}, but if I use alert(index) it recognize it. What is wrong?
Thanks in advanced
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I don't understand. What did you mean to happen, and what actually happened?

Let me remind you that the JSP (including JSTL) runs on the server and generates HTML, which may include Javascript. You didn't say whether this Javascript code was generated by the JSP or not. Then later, after that is all finished, the Javascript may run in the browser, on the client. You can't expect JSTL to do anything at this point.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

As the code contains Struts tags, this has been moved to the Struts forum. Please be sure to post any questions containing Struts artifacts to that forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bradusca Luisa
Greenhorn

Joined: Oct 28, 2009
Posts: 6
Paul Clapham wrote:I don't understand. What did you mean to happen, and what actually happened?

Let me remind you that the JSP (including JSTL) runs on the server and generates HTML, which may include Javascript. You didn't say whether this Javascript code was generated by the JSP or not. Then later, after that is all finished, the Javascript may run in the browser, on the client. You can't expect JSTL to do anything at this point.


Hi Paul, thanks for your reply!
Yes, the javascript code was generated by the JSP, and now I understant why ${} couldn't see my index variable because el is executed at server side and javascript at client side.
But how I can do what I meant to do that is: user selects a bean from a select option and I want to appear information about that bean in a div/span..-wich is:name,address,email and so on.(I allready have all the list generated in server side and also I have an index property so that I can choose easier listOfBeans.get(index).)
Thanks in advanced!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You either need to use Ajax, or build up all the JavaScript you need on the server side.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem using jstl in javascript