Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2 variable inside javascript

 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

I have a url coming from my action to the jsp, 'm getting the url in my jsp.

i have to open a pop up and have to pass that url to window.open() in javascript, but the problem is my url contains special characters which i need to rewrite with escape sequence character "\",
Q) How do i get the struts2 variable which i have set as <s:set name="myVar" value="strUrl"/> (strUrl containing special characters) to the javascript to append the escape character?

thanks in advance!!


Happy Developing.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OGNL allows arbitrary Java in the "value" attribute expression--just call whatever escaping library method you want to use.
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to disable HTML in order to display HTML, so I still have no idea what isn't working.

That aside, I already told you--if you're trying to create a string usable by JavaScript you use an OGNL expression in the "value" attribute to escape the Java string. One way would be to use commons-lang's "escapeJavaScript" method thusly:

 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THANKS !! SIR it worked fine. "value" i had missed !! Thanks again.
 
sankey jain
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robin John wrote:THANKS !! SIR it worked fine. "value" i had missed !! Thanks again.


hi Robin ,

I am having a similar error while using struts tag in javascript.


will the above solution apply to this ?
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Sankey...

I think it should work.

You can also set the variable first and then use it in your script using ognl.



I'll not be able to confirm the above as I can't test...
 
sankey jain
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robin John wrote:Hey Sankey...

I think it should work.

You can also set the variable first and then use it in your script using ognl.



I'll not be able to confirm the above as I can't test...


ok here is the funny thing.
i used the same thing on the property, and now i dont see the browser error.
Now, i want to see how the value looks like and i cant find the freakin code in the firebug.
it s got 12000 line of script.

running in loops

Nightmare !!

Anwyay.. think it worked..Thanks a ton
 
chets patel
Ranch Hand
Posts: 77
Eclipse IDE Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you please post your full jsp and javascript code. I am facing same issue and not able to solve.

Thanks in advance.
 
sankey jain
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the Total Jsp code. Use the function, it should solve it

chets patel wrote:can you please post your full jsp and javascript code. I am facing same issue and not able to solve.

Thanks in advance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic