Miles Daffin

Greenhorn
+ Follow
since Mar 20, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Miles Daffin

Amy,

I posted this same problem to the struts-users mail group and got this reply from David Friedman (tried & tested):

---
Miles,

Validation based on actions has that slash-in-the-name related problem. You can specify a name for the validation method using the html:javascript attribute method="...". Just be sure to change your html:form's onsubmit to invoke that new method name. For example:

<html:javascript formName="/someActionName" method="validateForm" /> <html:form action="..." ... onsubmit="return(validateForm(this));">

Just use the name "validateForm" or change it to any valid JavaScript method name of your choice. For more details see:

http://forum.java.sun.com/thread.jspa?forumID=45&messageID=2674439&threadID=
548445
http://homepage2.nifty.com/ymagic/struts/OtherTranslate/StrutsValidator/jspt
ags-jp.html

Regards,
David
---
19 years ago
The best answer I have seen to this was from Chris Felaco on jguru:

http://www.jguru.com/faq/view.jsp?EID=471957

I will quote it here just in case:
---
There is a very simple solution to the checkbox problem. The trick is to always add a hidden field AFTER the checkbox with the same parameter name but with the value set to "false":

<html:checkbox property="booleanProperty" value="true" />
<input type="hidden" name="booleanProperty" value="false">

Basically, the hidden parameter ensures that there is some request parameter submitted, which will always set the corresponding ActionForm property. If the checkbox is checked, the 2 parameters will be passed: "booleanProperty=true&booleanProperty=false". But the beanutils code only uses the first parameter to set the value. If the checkbox is left unchecked, then there will be only 1 parameter "booleanProperty=false" which will ensure the property is set.

The HTML spec says that form elements must be submitted in the GET or POST in the order that they are specified in the HTML, and all browsers I have used obey this rule. There is no risk that the hidden parameter will obscure the form field as long as you always put it after the checkbox.

The beauty of this solution is that it places the burden in the hands of the page author where there can be more flexibility. It also allows the page author to invert the meaning of the checkbox without bothering the application developer. All the page author needs to do is reword the caption, and switch the ordering of the values used in the checkbox and hidden fields. Also, it works with string or numeric properties just as easily.
---
19 years ago
I reckon this must be a bug - and a pretty reasonable one. I will raise it at the struts site.
19 years ago
I have this problem at the moment but ONLY when I run tomcat5 under jre 1.3.1_08. If I run tc under a 1.4 jre (j2sdk1.4.2_05 to be precise) the error disappears.

Any ideas?
19 years ago