File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts and javascript

 
Raistlin Zischer
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok here's what I'm trying to do. On the load of a page (RunThis.jsp), I want a collection of ojbects to be iterated through and create a link for each option. I have this done with the following code.

This works fine, besides that I can't get the "num" part of the struts link tag to be processed right. In the source code it comes out as "num" instead of the current value of num for the current iteration of the collection.

This is the javascript function code block I'm using for the select_onFocus


I'm sure if I could get the num to be parsed right I could get the rest of the code to work.
 
alan do
Ranch Hand
Posts: 354
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you want to get the current iteration, use the varStatus attribute of the c:forEach. set the varStatus to something like 'myStatusVariable' and use ${myStatusVariable.count}.
 
Raistlin Zischer
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I don't have any problems getting the current iteration. My problem is whenever I war my app up and go to run the my .jsp page, anything I put inside of the onfocus statement comes out exactly as what I put in it (i.e. with onfocus="select_onFocus(${myStatusVar})", the myStatusVar does not get PARSED. It looks exactly the same in the source code.

Is there anyway of using sturts or jstl vars inside of javascript code and still have the vars parsed right?
 
Slava Lovkiy
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since javascript is the regular text in html and not a tag attribute, you should use the <c ut> to place the value of required bean.
For the example above, try to do this:


In this case, first, the jstl tag output will be processed and than pasted into result html output.
 
Raistlin Zischer
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried that approach and still has the source code look word for word as I have written it in the jsp page. Can this be because of the order I have the libraries imported into my jsp page?

Also.....

should be

The double quotes inside of the javascript function causes errors.

[ September 23, 2005: Message edited by: Raistlin Ziker ]

[ September 23, 2005: Message edited by: Raistlin Ziker ]
[ September 23, 2005: Message edited by: Raistlin Ziker ]
 
alan do
Ranch Hand
Posts: 354
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh...that problem. html taglib does not support expression language. you may want to use the equivalent html_el taglib instead (http://struts.apache.org/faqs/struts-el.html).
 
Raistlin Zischer
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fixed the problem. I had to use a standard anchor tag in order to get it to work correctly. I have now come to another problem, this one dealing with struts form tag and javascript's onClick command. I've posted a topic in the javascript forum talking about this problem. If you think you can help, please take a look at it there, as I do NOT want to do duplicate posts.

Thanks for the help.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic