Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing a bean property as a parameter to html:multibox's onclick javascript

 
Riya Pant
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
i am new to Struts and was using <html:multibox> in my jsp.I have to pass two bean properties to my Action when a checkbox is selected.One property i sent using body part of <html:multibox> tag.For second property, i wrote a javascript method which to be invoked when clicking a checkbox.
The problem i was facing is-
Bean property passed as argument to that javascript method is not being evaluated to its value.Its being passed as an string.
Example code is below to better understand the problem :-)

<bean efine id="prop22" name="bean" property="prop2"/>
<html:multibox name="myForm" property="selectedCheckbox" on click="javascript:findSelectedIndex(this.form,'<%=prop22%>');">
<bean:write name="bean" property="prop1"/>
</html:multibox>
If prop22 is having value "123XYZ", the value got by javascript method is '<%=prop22%>' not "123XYZ".

Looking for ur responses
Thanks in advance
 
Ish Rawal
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Riya,
I got ur problem but can you please send me the complete code, so that i could check where the problem is?
[ February 17, 2006: Message edited by: Ish Rawal ]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use run-time expressions within a Struts <html:xxx> tag, but it's all or nothing: meaning that the whole entry must be a run-time expression or none of it must be a run-time expression. If you code the following, it should work:

oclick='<%= "javascript:findSelectedIndex(this.form,'"+prop22+"');"%>'
 
Brent Sterling
Ranch Hand
Posts: 948
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not a JSP expert. I have looked a few times but I have not seen a good book or article that talked about how custom tags and scriptlets interact and when they are evaluated. I tend to try out different things until they work. With that said, I searched through the code base for my project.

I see a few examples where bean:define is used along with standard html tags. All the examples that I found that use struts tags define the scripting variable in a scriptlet. You could try something like this and see if it works:



- Brent
 
Brent Sterling
Ranch Hand
Posts: 948
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see that Merrill submitted a reply while I was typing. Yea, I guess in all the examples that I found the entire attribute value is a run-time expression.

- Brent
 
Riya Pant
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Merill!
I tried this and its working now.Thanks a lot.
Cheers :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic