RE: Struts Validator 1.1 -- Solution WIll Not WOrk
The solution given below does not work for the case I described. jsType.jsp defines one form with several masked field validations. The example I'm having difficulty with is multiple forms with multiple fields with masked field validation which causes the Struts Validator to generate multiple versions of the function function mask () {} for each of the validator:javascript entries shown below: (1) validator:javascript formName=form1 dynamicJavascript=true staticJavascript=false/ (2) validator:javascript formName=form2 dynamicJavascript=true staticJavascript=false/ The first validator tag generates the following code (note the function mask() ) SCRIPT LANGUAGE=Javascript1.1 !-- Begin var bCancel = false; function validateForm1(form) { if (bCancel) return true; else return validateMask(form); } function mask () { this.aa = new Array(field6, Field 6 is invalid., new Function (varName, this.mask=/^\\d{7}/; return this[varName];)); } // End -- /SCRIPT while the second validator tag generates the following code (note the additional function mask() : NAMING CONFLICT ) SCRIPT LANGUAGE=Javascript1.1 !-- Begin var bCancel = false; function validateOmpModel(form) { if (bCancel) return true; else return validateRequired(form) validateMask(form) validateMaxLength(form) validateMinLength(form) validateInteger(form) validateRange(form); } function mask () { this.aa = new Array(field1, Field 1 is invalid., new Function (varName, this.mask=/^\\d{6}/; return this[varName];)); this.ab = new Array(field2, Field 2 is invalid., new Function (varName, this.mask=/^[ALST]/; this.maxlength='1'; return this[varName];)); this.ac = new Array(field3, Field 3 is invalid., new Function (varName, this.mask=/^\\d{6}/; this.maxlength='6'; return this[varName];)); this.ad = new Array(field4, Field 4 is invalid., new Function (varName, this.mask=/^\\d{1}/; return this[varName];)); this.ae = new Array(field5, Field 5 is invalid., new Function (varName, this.mask=/^\\c{1}/; return this[varName];)); } // End -- /SCRIPT In the static JavaScript generated by the following tag script language=JavaScript1.1 src=../includes/staticStrutsValidatorJavascript.jsp/script staticStrutsValidatorJavascript.jsp %@ page language=java % %-- set document type to Javascript (addresses a bug in Netscape according to a web resource --% %@ page contentType=application/x-javascript % %@ taglib uri=/WEB-INF/struts-validator.tld prefix=validator % validator:javascript dynamicJavascript=false staticJavascript=true/ - the problem lies in the last statement shown in the code listing below which is defined in validator-rules.xml and generated by the static JavaScript validator name=mask classname=org.apache.struts.validator.util.StrutsValidator method=validateMask depends=required msg=errors.invalid javascript![CDATA[ function validateMask(form) { var bValid = true; var focusField = null; var i = 0; var fields = new Array(); oMasked = new mask(); When the function runs the line oMasked = new mask();, it always retrieves the second mask() and thereby errs when attempting to validate the first form since (in the example I gave above), there is no field by the name of field6 in the second function mask() instance ( I get a JavaScript error on the following line form[oMasked[x][0]].value since form[oMasked[x][0]] is undefined ). I hope I have been clearer about the problem now. The solution I had in mind was to modify the Struts Validator to generate custom validation functions. So, for the example I gave above, it would generate the following functions: function maskForm1() { } function maskForm2() { }
RE: Struts Validator 1.1 -- Solution WIll Not WOrk
Sorry, there isn't a way to change this now. You could file it in bugzilla as a feature request. David --- [EMAIL PROTECTED] wrote: The solution given below does not work for the case I described. jsType.jsp defines one form with several masked field validations. The example I'm having difficulty with is multiple forms with multiple fields with masked field validation which causes the Struts Validator to generate multiple versions of the function function mask () {} for each of the validator:javascript entries shown below: (1) validator:javascript formName=form1 dynamicJavascript=true staticJavascript=false/ (2) validator:javascript formName=form2 dynamicJavascript=true staticJavascript=false/ The first validator tag generates the following code (note the function mask() ) SCRIPT LANGUAGE=Javascript1.1 !-- Begin var bCancel = false; function validateForm1(form) { if (bCancel) return true; else return validateMask(form); } function mask () { this.aa = new Array(field6, Field 6 is invalid., new Function (varName, this.mask=/^\\d{7}/; return this[varName];)); } // End -- /SCRIPT while the second validator tag generates the following code (note the additional function mask() : NAMING CONFLICT ) SCRIPT LANGUAGE=Javascript1.1 !-- Begin var bCancel = false; function validateOmpModel(form) { if (bCancel) return true; else return validateRequired(form) validateMask(form) validateMaxLength(form) validateMinLength(form) validateInteger(form) validateRange(form); } function mask () { this.aa = new Array(field1, Field 1 is invalid., new Function (varName, this.mask=/^\\d{6}/; return this[varName];)); this.ab = new Array(field2, Field 2 is invalid., new Function (varName, this.mask=/^[ALST]/; this.maxlength='1'; return this[varName];)); this.ac = new Array(field3, Field 3 is invalid., new Function (varName, this.mask=/^\\d{6}/; this.maxlength='6'; return this[varName];)); this.ad = new Array(field4, Field 4 is invalid., new Function (varName, this.mask=/^\\d{1}/; return this[varName];)); this.ae = new Array(field5, Field 5 is invalid., new Function (varName, this.mask=/^\\c{1}/; return this[varName];)); } // End -- /SCRIPT In the static JavaScript generated by the following tag script language=JavaScript1.1 src=../includes/staticStrutsValidatorJavascript.jsp/script staticStrutsValidatorJavascript.jsp %@ page language=java % %-- set document type to Javascript (addresses a bug in Netscape according to a web resource --% %@ page contentType=application/x-javascript % %@ taglib uri=/WEB-INF/struts-validator.tld prefix=validator % validator:javascript dynamicJavascript=false staticJavascript=true/ - the problem lies in the last statement shown in the code listing below which is defined in validator-rules.xml and generated by the static JavaScript validator name=mask classname=org.apache.struts.validator.util.StrutsValidator method=validateMask depends=required msg=errors.invalid javascript![CDATA[ function validateMask(form) { var bValid = true; var focusField = null; var i = 0; var fields = new Array(); oMasked = new mask(); When the function runs the line oMasked = new mask();, it always retrieves the second mask() and thereby errs when attempting to validate the first form since (in the example I gave above), there is no field by the name of field6 in the second function mask() instance ( I get a JavaScript error on the following line form[oMasked[x][0]].value since form[oMasked[x][0]] is undefined ). I hope I have been clearer about the problem now. The solution I had in mind was to modify the Struts Validator to generate custom validation functions. So, for the example