Hi, I am doing validation of my form bean using struts validation framework. My actionform is getting populated by two jsps, first one is having four fields and second jsp is having same no. of fields as in actionform.
I am validating all fields of my form in validation.xml file. For my second jsp, there is no problem. Validation is fine. But for the first JSP, jsp form fields are less than action form instance fields. Since I am using required rule on some field therefore I am getting validation error for those extra actionform fields which are not in my first jsp.
One way could be by using html:hidden fields in the first form for those extra fields and pass some default values so that validation gets bypassed firts time.
Is there any other way of doing it? What about validwhen validator rule?
Struts looks up the attribute stored against mapping.getName(), initialises the validator with this object and then invokes the validations. So you can define the same action form class as two different form-beans and then use them accordingly in your action mapping and your validation.xml. This would let you perform different validations on the same action form class as the validations are not tied to the action form class but to the form-bean definitions.
The problem which I am facing is that I have just one action which is mapped to form bean and I am using the same action in two jsps, so even if I specify the action in validation.xml file instead of form name, there is no difference.
Yes If I use two different actions in struts-config file, then sure ValidatorActionForm will work.
Let me tell you I am doing it by passing a hidden field in both jsp like below:
<html:hidden property="page" value="1"/>
And in validation.xml file, field tag has a page attribute which tells you which fields are validated client side and which fields on the server side.
Fields which I don't want to be validated in the first jsp, I pass its value more than current page value, then in that case, validations will be on client side instead of server side. Since I am not validating it on client side, it will just pass.
Any comments? [ March 14, 2007: Message edited by: Naseem Khan ]
subject: Validating some extra fields of action form not in my jsp?