Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts and Dynamic Javascript

 
vicky kumar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm using struts 1.0. I need to generate Javascript dynamically. It is not for validation. On onChange event of select-box I need to change value of a textfield. And these values are known until run time.
Can someone suggest me best way to achieve it. Should I have a method in my action form that generates a string of javascript. Is this efficient though ?
Do let me know some other strategies or ideas.
Would really appreciate that.

Thanks
Vicky
 
Balan Raj
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you know the values at run time why dont you use a combination of JS & scriplet ?

You could do something like


Maybe u can populate this at the end of the page ?
 
vicky kumar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am able to generate javascript through a method (say getMyJs()) in my ActionForm. But I am haing weird problem.
For example: to generate aleart ('I am here') I use the following java code:

StringBuffer buff = new StriingBuffer()
...
buff.appen("alert("' I am here'");

All I get in resultant JSP code (when I see view source) is '. So my alert looks like this

alert('I am here' ;

and this fails, as Javascript is unable to identify it.

Does any have any idea / experience on how to pring Single Quote (') in Javascript through Java code (inside my struts action form).

I have already spent a whole day in this seemingly simple problem.

Cheers
Vicky
 
Balan Raj
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case you haven't resolved it yet

1. Play around with single & double quotes.. JS accepts single quote


2. Use escape characters to achieve that

[ September 28, 2004: Message edited by: Balan Ram ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic