aspose file tools*
The moose likes Struts and the fly likes passing a bean property as a parameter to html:multibox's onclick javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "passing a bean property as a parameter to html:multibox Watch "passing a bean property as a parameter to html:multibox New topic
Author

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

Riya Pant
Greenhorn

Joined: Feb 17, 2006
Posts: 28
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

Joined: Feb 07, 2006
Posts: 2
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 ]

Ish Rawal<br /> <br />"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster"
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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+"');"%>'


Merrill
Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
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

Joined: Feb 08, 2006
Posts: 948
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

Joined: Feb 17, 2006
Posts: 28
Hi Merill!
I tried this and its working now.Thanks a lot.
Cheers :-)
 
 
subject: passing a bean property as a parameter to html:multibox's onclick javascript