Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

STRUTS:client-side validation using validation.xml for hidden field results in error

 
Tanveer Rameez
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I am using client-side validation in a JSP in struts environment.
The script to enable client-side validation in the JSP form is :

My validation conditions are:
1. age>18 and age <75
2. term>0 and term <40
3. (age+term) <80
I have one <html:text property="age"> for age and another <html:text property="term"> for term. Now to hold the value of (age+term) i have a <html:hidden property="ageTermSum"> whose value is set to (age+term) before submission by a java script.
Now in the validation.xml i have this code:


I get javascript error when validation for ageTermSum fails (i.e if age+term >80). When I change the hidden field to a textfield it works fine. That is, if i replace <html:<b>hidden</b> property="ageTermSum"> by
<html:<b>text</b> property="ageTermSum"> and if the validation for that property fails, I get a alert message indicating the error. and then the focus goes to the textfield ;. This is usually how client-sdie validation in struts happens..i.e. the focus goes to the field with error.
So what I can guess is that, when the field is hidden type, focus cannot go to that field and so javascript error occurs. Am I right?
If so can I prevent the focus from going to that field only or is that any other approach?
Thanks
Tanveer
[ August 27, 2004: Message edited by: Tanveer Rameez ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic