Niall,

Derek isn't crazy and this looks like a bug to me IF your args try to use
'resource="true"'.  I duplicated the problem using Struts 1.2.4 with the
commons validator 1.1.3 and 1.1.4 jars.  Sadly, the java code suggests
resource="true" works in 1.1.4 but I can't get it to work even with a new
1.1.4 testing jar AND fully stopping/restarting Tomcat 5.5.4.  Essentially,
I'm seeing resource="true" use the message resources to fill out the error
fields on both the client and server sides, just not populating the vars for
the client or server side validations to be able to use them.

For example, using this rule, call it "rule A", everything works normally on
the client and server sides:

<form name="testingForm">
    <field property="name" depends="required, minlength, maxlength">
        <arg0 key="testingForm.name"/>
        <arg1 name="minlength" key="${var:minlength}" resource="false" />
        <arg1 name="maxlength" key="${var:maxlength}" resource="false" />
        <var><var-name>minlength</var-name><var-value>7</var-value></var>
        <var><var-name>maxlength</var-name><var-value>20</var-value></var>
    </field>
</form>

Modifying this into "rule B", the validation will not work on the client
side OR the server side, BUT the error messages show the appropriate message
resources numbers and words (for the arg0 field name, for example).  Here is
"rule B":

<form name="testingForm">
    <field property="name" depends="required, minlength, maxlength">
        <arg0 key="testingForm.name"/>
        <arg1 name="minlength" key="testingForm.name.min" resource="true" />
        <arg1 name="maxlength" key="testingForm.name.max" resource="true" />
    </field>
</form>

My message resources file works properly (tested thoroughly) with:
testingForm.name=Name
testingForm.name.min=7
testingForm.name.max=20

At: /WEB-INF/classes/resources/Application.properties
In struts-config.xml as:
<message-resources parameter="resources.Application" null="false" />

Here is the lower level stuff showing the problem.  With "rule A", our
Validation methods set maxlength, minlength, etc. properties as expected in
the JavaScript such as:

function ValidationForm_required () {
     this.a0 = new Array("name", "Name is required.", new Function
("varName", "this.maxlength='20'; this.minlength='7';  return
this[varName];"));
    }

    function ValidationForm_minlength () {
     this.a0 = new Array("name", "Name can not be less than 7 characters.",
new Function ("varName", "this.maxlength='20'; this.minlength='7';  return
this[varName];"));
    }

    function ValidationForm_maxlength () {
     this.a0 = new Array("name", "Name can not be greater than 20
characters.", new Function ("varName", "this.maxlength='20';
this.minlength='7';  return this[varName];"));
    }

And in the server-side Java Field object:

Field:
                key = name
                property = name
                indexedProperty = null
                indexedListProperty = null
                depends = required, minlength, maxlength
                page = 0
                fieldOrder = 0
                Vars:
                        maxlength=Var: name=maxlength  value=20  jsType=null

                        minlength=Var: name=minlength  value=7  jsType=null

However, set the resource="true" as in "rule B", and you are missing that
information on both the client side and the server side:

 function ValidationForm_required () {
     this.a0 = new Array("name", "Name is required.", new Function
("varName", " return this[varName];"));
    }

    function ValidationForm_minlength () {
     this.a0 = new Array("name", "Name can not be less than 7 characters.",
new Function ("varName", " return this[varName];"));
    }

    function ValidationForm_maxlength () {
     this.a0 = new Array("name", "Name can not be greater than 20
characters.", new Function ("varName", " return this[varName];"));
    }

And for the server-side your Field object ALSO lacks the variables:

Field:
                key = name
                property = name
                indexedProperty = null
                indexedListProperty = null
                depends = required, minlength, maxlength
                page = 0
                fieldOrder = 0
                Vars:

End result, "rule A" works on both sides while "rule B" fails on both sides
but does correctly populate the error fields with the message parameters.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Additionally, I don't like the redundancy.  Using the above illustrations,
this.a0 is set in EVERY method.  Can't we consolidate this so it is setup
once something like the below and have that put into the main
"validateWhateverForm(form)" method after checking that bCancel is false and
before the validation checks?

this.a0 = new Array("name", new Function ("varName", "this.maxlength='20';
this.minlength='7';  this.error.minlength='Name can not be less than 7
characters.'; this.error.maxlength='Name can not be greater than 20
characters.';return this[varName];"));

The 2 differences being:

a) All errors are in one place under this.error.VALIDATIONTYPE such as
this.error.minlength, this.error.maxlength, this.error.required,
this.error.intRange, etc. instead of being Array index 1 (if starting from a
zero array index position)

b) Initialization for each object is in one place.  Since the JavaScript
appears to look for an object matching the first name of the Array anyway,
wouldn't this be cleaner and less redundant?

Should I post the top part and/or the bottom part to Buzilla?  Which one?
Commons or Struts?  Opinions are requested on this one plus a few more
people to triple check this by performing their own simple tests like mine.

Regards,
David

-----Original Message-----
From: Niall Pemberton [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 01, 2004 8:11 PM
To: Struts Users Mailing List
Subject: Re: Problem with validation using both minlength and maxlength
on the same field


You need to specify maxlength and minlength variables.

          <field
            property="myField"
            depends="minlength, maxlength, integer">
            <arg0 key="sampleApp.myField.label"/>
            <arg1 key="sampleApp.myField.minLen" name="minlength"  />
            <arg1 key="sampleApp.myField.maxLen" name="maxlength"  />
            <var>
                 <var-name>minlength</var-name><var-value>10</var-value>
            </var>
            <var>
                 <var-name>maxlength</var-name><var-value>20</var-value>
            </var>

Alternatively, if its an integer field you could use the intRange validator
instead

          <field
            property="myField"
            depends="integer,intRange">
            <arg0 key="sampleApp.myField.label"/>
            <arg1 key="${var:min}" resource="false"  />
            <arg2 key="${var:max}" resource="false"  />
            <var>
                 <var-name>min</var-name><var-value>10</var-value>
            </var>
            <var>
                 <var-name>max</var-name><var-value>20</var-value>
            </var>


Niall

----- Original Message -----
From: "David G. Friedman" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Thursday, December 02, 2004 12:46 AM
Subject: RE: Problem with validation using both minlength and maxlength on
the same field


> Derek,
>
> I'm seeing the same thing you described.  I'm sorry I didn't believe you.
> Sadly, I'm having a HELL of a time figuring out what's wrong because I
> recently upgraded my development setup to Struts 1.2.4 and Tomcat 5.5.4
and
> haven't used validation in a while.  Trying the 1.1.4 validator binary
> didn't help any.  I'm feeling really stupid since used to be able to get
> this to work.  Too many variables have changed on me. *sigh*
>
> Regards,
> David
>
> -----Original Message-----
> From: Derek Broughton [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, December 01, 2004 1:18 PM
> To: Struts Users Mailing List
> Subject: Re: Problem with validation using both minlength and maxlength
> on the same field
>
>
> On Wednesday 01 December 2004 13:49, [EMAIL PROTECTED] wrote:
> > I'm trying to validate a simple field.  I want to validate that the
field
> > is an integer, and meets the min and max length requirements.  In the
same
> > application I am able to correctly validate a date field so I'm
confident
> > my overall struts setup is correct.  However when I try to do both a min
> > and max length check on the same field, the max length check doesn't
work.
> >  If I exceed the max length I get the min length message.  Below is a
> > snippet from my validation.xml file.  I've setup my properties file to
> > include the min and max length constants.
> >
> > validation.xml
> > ...
> > ...
> >          <field
> >            property="myField"
> >            depends="minlength, maxlength, integer">
> >            <arg0 key="sampleApp.myField.label"/>
> >            <arg1 key="sampleApp.myField.minLen" name="minlength"  />
> >            <arg1 key="sampleApp.myField.maxLen" name="maxlength"  />
>
> Despite two other good looking answers, I'd have to say that it seems
> unlikely
> that these should _both_ be "arg1" :-)
> --
> derek
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to