This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
We have jsp files with mutiple screens and each having user inputs. we tried to use the validator framework to do the server side and client side validation.
The problem we are facing is server side validatin is triggered even before we input the data, since request goes to the Action class before jsp.
i want to know, is there a machanism to specify when the validation should happen.
And i want to validate only the fields in screen1 for the first request.And the fields in 2nd screen when the 2 request is submitted.(note that all the screens are written in single jsp). can this be done in struts.
we are using struts 1.1
when you really want something, all the universe always conspires in your favour.<br /> <br />SCJP1.5-77%<br />SCWCD-89%
Originally posted by Senthil Kumar SS: The problem we are facing is server side validatin is triggered even before we input the data, since request goes to the Action class before jsp.
Make sure you have a separate preparatory Action mapping that does this. Then simply sepecify validate="false" for this Action mapping in the struts-config.xml file.
Originally posted by Senthil Kumar SS: And i want to validate only the fields in screen1 for the first request.And the fields in 2nd screen when the 2 request is submitted.(note that all the screens are written in single jsp). can this be done in struts.
we are using struts 1.1
Try looking in the documentation for the page attribute of the field element in the validation.xml file. You may be able to use this to validate differently for each page. See the heading Multi Page Formsin this link.
Despite of passing the page value as "5" , validation gets executed for the second jsp(both jsp's are using the same form).And we get the validation messages in the second jsp.
Our doubt is, will the value passed through page hidden element visible in validation.xml.Because the log in my form bean is not getting printed.
Joined: Feb 15, 2005
It looks like you have not understood how the page attribute works. Here is a quote from the documentation:
All validation for any field on a page less than or equal to the current page is performed server side
That means that if you define page=1 for a field in your validation.xml, and the current page is five, the field will be validated, since 5 is greater than 1.
The assumption is that the ActionForm is in session scope, and that you're keeping the values entered from previous pages. If you do this, fields defined for page 1 will pass validation, since you still have the value the user entered in page 1.
Joined: Mar 13, 2006
All validation for any field on a page less than or equal to the current page is performed server side.
I thought that Merrill has already done a good job of helping you. What are your specific questions? Do you understand that if the page value is 5 then validation will be executed for pages 1, 2, 3, 4 and 5? Are you keeping your form in session scope? If not then the built in "page" support of the validator framework might not work for you.
When I have implemented Validation in wizard pages I implemented it myself in the validate method of the form. If you were using Struts 1.2+ then you could probably do this with the validwhen rule. I have wondered how much work it would be to change the validation so that the page validation was only executed for the current page. I am not sure if there are extension points or if you would have to change Struts code and recompile.