hi there,
I've noted an issue with the validator-rules.xml:
Right now Javascript validation is done sequentially for each datatype.
e.g. formValidationResult = formValidationResult = validateRequired(form)
&& validateByte(form) && validateShort(form) ...;
This means first all required fields have to be entered, and then the
field datatype validations will start and so on.
>From a user-point-of-view this is not immediately obvious. A user would
say that it's preferable to have each field validated as soon as it is
possible.
Additionally, the user will face many javascript-alerts until he is able
to submit the form (as byte validations come first and then will come
integer validations etc.)
You can easily try this out using the
/struts-examples/validator/editJsType.do and enter invalid data into the
short, the integer and the float field. You'll get one alert as you fix
each field.
However, the solution to this is really easy:
Add two parameters to each validate<datatype>() function:
e.g. validateRequired(form, errorFieldNames, errorFieldMessages) and set
these parameters inside of each validation function:
// old implementation: fields[i++] = oRange[x][1];
// new dynamic implementation:
errorFieldNames[errorFieldNames.length] = field.name;
errorFieldMessages[errorFieldMessages.length] = oRange[x][1];
then, set up the following code to do the validation in your form:
function validateMyFormExtended(form) {
var errorFieldNames = new Array();
var errorFieldMessages = new Array();
if (!bCancel) {
// each validation routine will add error messages as they occur.
validateRequired(form, errorFieldNames, errorFieldMessages);
validateInteger(form, errorFieldNames, errorFieldMessages);
//... do validation for each datatype
// this will do ONE alert for all validation errors that have
occured.
if (errorFieldNames.length>0) {
alert(errorFieldMessages.join('\n'));
}
}
}
I've already patched struts-1.1 this way and can send the full javascript
code to anyone interested.
In the latest nightly build validator-rules.xml has been split to use
commons-validator-1.1.3.jar, but the javascript files there have stayed
the same.
Best regards,
J. Fiala