Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dyanmic part of the script tag does not get evaluated

 
Roger Rodrigues
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9527
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Roger Rodrigues
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9527
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic