This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts and javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts and javascript" Watch "Struts and javascript" New topic
Author

Struts and javascript

Raistlin Zischer
Greenhorn

Joined: Jul 05, 2005
Posts: 25
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

Joined: Apr 14, 2005
Posts: 354
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}.


-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
Raistlin Zischer
Greenhorn

Joined: Jul 05, 2005
Posts: 25
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

Joined: Aug 17, 2005
Posts: 29
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

Joined: Jul 05, 2005
Posts: 25
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

Joined: Apr 14, 2005
Posts: 354
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

Joined: Jul 05, 2005
Posts: 25
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.
 
jQuery in Action, 2nd edition
 
subject: Struts and javascript