| Author |
struts validator. stoping on first validation error.
|
suman maity
Greenhorn
Joined: Jan 30, 2007
Posts: 1
|
|
I am using struts validator framework for both client and server side validations. The problem is validations of the same type occur together. But I want all validations for a particular field to be finished first and if that field passes all validations, then only validations for the next field should take place and so on. ex: say I have two text fields. field 1: validations are: required, mask (checks a regular expression) field 2: validations are : required, integer if both the fields are empty,on click of submit button an alert is shown as: field 1 is required field 2 is required but I want validation to stop after reporting validation error for field 1 only. Once both the validations for field 1 are done, then only it should alert for the second field. Please help. I also tried with the "stopOnError" property in the plug-in tag in struts-config.xml, but it didn't work out.
|
 |
Milan Jagatiya
Ranch Hand
Joined: Jan 01, 2007
Posts: 164
|
|
|
can you post code snippets for validation.xml and your jsp file...
|
Milan.<br />I can because I think I can...
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
In order to do this, you're going to have to write custom code. Here's what I'd suggest: Use your browser's "view source" function to look at the rendered HTML page including the JavaScript that Struts creates for client-side validation.Analyse the code and observe how the various validation functions are calledCreate your own MyValidate function that performs the validations the way you want them done. Your function can still call the struts validation functions, but in a different order.Change the onsubmit event of the <html:form> tag to point to your function.
|
Merrill
Consultant, Sima Solutions
|
 |
Brent Sterling
Ranch Hand
Joined: Feb 08, 2006
Posts: 948
|
|
I did a little searching around for that stopOnError setting (is it actually stopOnFirstError?). Looking at the source code for ValidatorPlugIn.java I see the following quotes: "Informs the Validators if it has to stop validation when finding the first error or if it should continue. Default to true to keep Struts 1.1 backwards compatibility." "A boolean indicating whether JavaScript validation should stop when it finds the first error (Struts 1.1 behaviour) or continue validation." In the Struts 1.2.4 release notes I see the following quote: "You can now force the clientside Javascript validation to check all constraints, instead of stopping at the first error. By setting a new property, stopOnFirstError, on the Validator PlugIn to false." I have to admit that I have never used client-side JavaScript validation. Is the default behavior to show an alert box with all the fields that failed validation or just the first one? - Brent
|
 |
 |
|
|
subject: struts validator. stoping on first validation error.
|
|
|