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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to