You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mi...@bmwna.com on 2002/06/11 14:48:04 UTC

Struts Validator 1.1

Does the Struts Validator  v1.0 or v1.1 allow multiple page form
validations?

I have a page with two forms, each requiring validation before submission.

	Form 1: <html:form action="form1Action.do" method="post"
onsubmit="return validateForm1(this)">
				
	Form 2: <html:form action="form2Action.do" method="post"
onsubmit="return validateForm2(this)" >

Both of these forms contain one field that requires a mask validation.

However, version 1.0 of the Struts Validator which I am using generates two
JavaScript functions 

		<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("field1", " is invalid.", new
Function ("varName", "this.mask=/^\\d{7}/;  return this[varName];"));
			 } 
		//  End -->
		</SCRIPT>

		<SCRIPT LANGUAGE="Javascript1.1"> 
		<!-- Begin 

	 		var bCancel = false; 

	 		function validateForm2(form) {

	     		 if (bCancel) 
	 			return true; 
	      		else 
	 			return validateMask(form); 
	 		} 

			 function mask () { 
	   		 this.aa = new Array("field2", "Field 2 is
invalid.", new Function ("varName", "this.mask=/^\\d{6}/;  return
this[varName];"));
	    		this.ab = new Array("field3", "Field 3 is invalid.",
new Function ("varName", "this.mask=/^[ALST]/; this.maxlength='1';  return
this[varName];"));
	    		this.ac = new Array("field4", "Field 4 is invalid.",
new Function ("varName", "this.mask=/^\\d{6}/; this.maxlength='6';  return
this[varName];"));
	 		} 
		//  End -->
		</SCRIPT>

By defining two functions both with the same name ( i.e. function mask ),
the Struts Validator 1.0 prevents me from performing validation on multiple
forms on the same page with the same validation rules (i.e. mask in this
case).

Any suggestions or workarounds?  If v1.0 does not support this, does v1.1
address this issue by generating unique function names per form?

Any help is greatly appreciated.

Thanks.

Michael

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Struts Validator 1.1

Posted by David Winterfeldt <dw...@yahoo.com>.
Creating a Separate Page for Static JavaScript
If you want to just generate the dynamic JavaScript on
you form page and have a separate page with the static
JavaScript to take advantage of browser caching you
can use the dynamicJavascript and staticJavascript
attributes to the JavascriptValidatorTag. You can turn
each attribute's generation of JavaScript on and off
by putting in true or false (they default to true).
Reference jsType.jsp and staticJavascript.jsp in the
main example webapp for a working example.

In your form page:
    <validator:javascript formName="typeForm"
dynamicJavascript="true" staticJavascript="false"/>
    <script language="Javascript1.1"
src="staticJavascript.jsp"></script>

    This wouldn't work right in IE 5.0 when I made the
source an attribute of the tag.

In your static JavaScript page.
    <%@ page contentType="application/x-javascript" %>
    <validator:javascript dynamicJavascript="false"
staticJavascript="true"/>

http://home.earthlink.net/~dwinterfeldt/jsptags.html

There is an example of this in the example webapp.

David

--- Michael.Kashambuzi@bmwna.com wrote:
> 
> Does the Struts Validator  v1.0 or v1.1 allow
> multiple page form
> validations?
> 
> I have a page with two forms, each requiring
> validation before submission.
> 
> 	Form 1: <html:form action="form1Action.do"
> method="post"
> onsubmit="return validateForm1(this)">
> 				
> 	Form 2: <html:form action="form2Action.do"
> method="post"
> onsubmit="return validateForm2(this)" >
> 
> Both of these forms contain one field that requires
> a mask validation.
> 
> However, version 1.0 of the Struts Validator which I
> am using generates two
> JavaScript functions 
> 
> 		<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("field1", " is invalid.",
> new
> Function ("varName", "this.mask=/^\\d{7}/;  return
> this[varName];"));
> 			 } 
> 		//  End -->
> 		</SCRIPT>
> 
> 		<SCRIPT LANGUAGE="Javascript1.1"> 
> 		<!-- Begin 
> 
> 	 		var bCancel = false; 
> 
> 	 		function validateForm2(form) {
> 
> 	     		 if (bCancel) 
> 	 			return true; 
> 	      		else 
> 	 			return validateMask(form); 
> 	 		} 
> 
> 			 function mask () { 
> 	   		 this.aa = new Array("field2", "Field 2 is
> invalid.", new Function ("varName",
> "this.mask=/^\\d{6}/;  return
> this[varName];"));
> 	    		this.ab = new Array("field3", "Field 3 is
> invalid.",
> new Function ("varName", "this.mask=/^[ALST]/;
> this.maxlength='1';  return
> this[varName];"));
> 	    		this.ac = new Array("field4", "Field 4 is
> invalid.",
> new Function ("varName", "this.mask=/^\\d{6}/;
> this.maxlength='6';  return
> this[varName];"));
> 	 		} 
> 		//  End -->
> 		</SCRIPT>
> 
> By defining two functions both with the same name (
> i.e. function mask ),
> the Struts Validator 1.0 prevents me from performing
> validation on multiple
> forms on the same page with the same validation
> rules (i.e. mask in this
> case).
> 
> Any suggestions or workarounds?  If v1.0 does not
> support this, does v1.1
> address this issue by generating unique function
> names per form?
> 
> Any help is greatly appreciated.
> 
> Thanks.
> 
> Michael
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>