You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Igor Marchenko <st...@mail.stcompany.ru> on 2003/11/27 13:05:35 UTC

BUG fix for org.apache.struts.taglib.html.JavascriptValidatorTag

	Hello all.

BUG
---
I use Struts's ValidatorPlagin in client validation manner. It generates an
JavaScript Array of field checks to made. Example:

function validatorRuleName () {
	this.aa = new Array(...));
	this.ab = new Array(...));
	this.ac = new Array(...));
	this.ad = new Array(...));
	this.ae = new Array(...));
	...
	this.do = new Array(...));
	...
	this.in = new Array(...));
	...
}

But "do" and "in" is JavaScript reserved words. Therefore if there is quite
a few field who need validation "this.do" and "this.in" appears (this is
syntax error).

FAST FIX
--------
Override org.apache.struts.taglib.html.JavascriptValidatorTag#getNextVar
method as here:

private String getNextVar(String input) {
	return "_"+(input==null?0:(Integer.parseInt(input.substring(1))+1));
}

DEEPER FIX
----------
It's clear, org.apache.struts.taglib.html.JavascriptValidatorTag#getNextVar
method is not needed. Remove them at all and correct
org.apache.struts.taglib.html.JavascriptValidatorTag#doStartTag method
correspondingly.

Replace next lines

String jscriptVar = null;
jscriptVar = this.getNextVar(jscriptVar);
results.append(
	"     this."
	+ jscriptVar
	+ " = new Array(\""
	+ field.getKey()
	+ "\", \""
	+ message
	+ "\", ");

with

int jscriptVar = 0;
results.append("     this.")
	.append(jscriptVar++)
	.append(" = new Array(\"")
	.append(field.getKey())
	.append("\", \"")
	.append(message)
	.append("\", ");

OTHER WORDS
-----------
I check both fix ways with big number (more than 100) of checks on one page.

Big thanx for all Struts developers.



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


Re: BUG fix for org.apache.struts.taglib.html.JavascriptValidatorTag

Posted by David Graham <gr...@yahoo.com>.
Thanks for the fix idea.  It would have been better if you posted this
directly to the bugzilla ticket though.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=24516

David


--- Igor Marchenko <st...@mail.stcompany.ru> wrote:
> 	Hello all.
> 
> BUG
> ---
> I use Struts's ValidatorPlagin in client validation manner. It generates
> an
> JavaScript Array of field checks to made. Example:
> 
> function validatorRuleName () {
> 	this.aa = new Array(...));
> 	this.ab = new Array(...));
> 	this.ac = new Array(...));
> 	this.ad = new Array(...));
> 	this.ae = new Array(...));
> 	...
> 	this.do = new Array(...));
> 	...
> 	this.in = new Array(...));
> 	...
> }
> 
> But "do" and "in" is JavaScript reserved words. Therefore if there is
> quite
> a few field who need validation "this.do" and "this.in" appears (this is
> syntax error).
> 
> FAST FIX
> --------
> Override org.apache.struts.taglib.html.JavascriptValidatorTag#getNextVar
> method as here:
> 
> private String getNextVar(String input) {
> 	return "_"+(input==null?0:(Integer.parseInt(input.substring(1))+1));
> }
> 
> DEEPER FIX
> ----------
> It's clear,
> org.apache.struts.taglib.html.JavascriptValidatorTag#getNextVar
> method is not needed. Remove them at all and correct
> org.apache.struts.taglib.html.JavascriptValidatorTag#doStartTag method
> correspondingly.
> 
> Replace next lines
> 
> String jscriptVar = null;
> jscriptVar = this.getNextVar(jscriptVar);
> results.append(
> 	"     this."
> 	+ jscriptVar
> 	+ " = new Array(\""
> 	+ field.getKey()
> 	+ "\", \""
> 	+ message
> 	+ "\", ");
> 
> with
> 
> int jscriptVar = 0;
> results.append("     this.")
> 	.append(jscriptVar++)
> 	.append(" = new Array(\"")
> 	.append(field.getKey())
> 	.append("\", \"")
> 	.append(message)
> 	.append("\", ");
> 
> OTHER WORDS
> -----------
> I check both fix ways with big number (more than 100) of checks on one
> page.
> 
> Big thanx for all Struts developers.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-dev-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org