File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes dyanmic part of the script tag does not get evaluated Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "dyanmic part of the script tag does not get evaluated" Watch "dyanmic part of the script tag does not get evaluated" New topic
Author

dyanmic part of the script tag does not get evaluated

Roger Rodrigues
Greenhorn

Joined: Oct 01, 2003
Posts: 3
Hi
I am new to struts and am stuck at a point.
I have my hello.jsp
...
...
<s:iterator status="toyCategory" value="#session.ToyCategory" >
<script src="/includes/js/dailyActivity.js" type="text/javascript" ></script>
</s:iterator>

The dynamic content in the js file does not get evalued , the property file is displayed as the server side code

dailyActivity.js
......
var id<s:property value="#toyCategory.index"/> This gets rendered when i check the view source page on the browser



But if i take the whole script and place it in the jsp it evaluates it fine .

Is there something else i need to add when i use the script tag ?

Thanks for your help
-roger
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Are you including struts tags in a JS file??? This will not work. If you need something like this, you can set the value of the required fields in the JSP page. Something like



This example will not work in this specific case as the id variable will be set to a new value multiple times with each iteration but since I don't know why you are including the same JS file multiple times (it seems unnatural to me) so I can't tell you a solution...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Roger Rodrigues
Greenhorn

Joined: Oct 01, 2003
Posts: 3
I am using struts2 . I am trying to have the struts tags in the .js file. and would like the content in the file be built dynamically. I do understand that the .js is executed in the browser side. so hence the dyanmic part in the js does not get executed.

This is my code
hh.js file


I can manually build this out and have no issues

In my jsp


the only way i have found this works is rename the .js to .jsp and then the server will take care of interpreting the struts2 tags
[code]
<script src="<s:url value="/includes/js/fof/hh.jsp"/>" type="text/javascript"></script>
[code]

Thats why i wanted to find out if there a way of mapping the .js to be intercepted by the interceptor or servlet ...
or is there another solution

thanks
Roger
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

In your JS file, you only need the index of the iteration. The solution is simple. Include the .js file only once, put all the code in the JS file in a function like this



Now in your JSP, call this method with every iteration like this

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: dyanmic part of the script tag does not get evaluated