You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adam Hardy <ah...@cyberspaceroad.com> on 2003/07/01 15:39:50 UTC

FieldChecks.validateMinLengths()

I started using struts validator. I just copied a bunch of stuff from 
the struts example and started using that, and found that the minlength 
validation actually returns true when the text field is blank.

This was my first attempt and I was trying to make sure I had got the 
validator plug-in functioning correctly, so I actually spent a few hours 
hunting down the reason why my blank field was passing validation even 
though the minlength had been set to 1.

I discovered in the source code that this is normal behaviour - surely 
that can't be the case? I would expect a blank field to fail validation 
for minimum length. Or is this actually the case for reasons I'm not 
aware of?

Thanks
Adam


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


Re: FieldChecks.validateMinLengths()

Posted by Nicolas De Loof <ni...@cgey.com>.
I think this is the correct behaviour since "blank" fields have to be considered using the "required" rule.

You can use both required + minlength rules if field is mandatory.

Nico.



> I started using struts validator. I just copied a bunch of stuff from 
> the struts example and started using that, and found that the minlength 
> validation actually returns true when the text field is blank.
> 
> This was my first attempt and I was trying to make sure I had got the 
> validator plug-in functioning correctly, so I actually spent a few hours 
> hunting down the reason why my blank field was passing validation even 
> though the minlength had been set to 1.
> 
> I discovered in the source code that this is normal behaviour - surely 
> that can't be the case? I would expect a blank field to fail validation 
> for minimum length. Or is this actually the case for reasons I'm not 
> aware of?
> 
> Thanks
> Adam
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org

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


Re: FieldChecks.validateMinLengths()

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Hi David
is there any reason to suspect I am doing something with the resource 
string as well?

With the all-up-to-date version :) I get the correct validation message 
for the minvalue, but the maxvalue msg says:

Title cannot be greater than null characters

Any pointers?

Adam

Adam Hardy wrote:
> I'm sorry, it was my fault. I had forgotten to replace the 
> validator-rules.xml with the new version.
> 
> David Graham wrote:
> 
>> Remove the <field bundle> attribute because that's not supported.  What
>> text are you typing into the input box?
>>
>> David
>>
>> --- Adam Hardy <ah...@cyberspaceroad.com> wrote:
>>
>>> <formset>
>>>     <form name="sectionForm">
>>>       <field property="id"
>>>         depends="integer">
>>>         <arg0   key="sections.validate.id"/>
>>>       </field>
>>>       <field property="title"
>>>         depends="minlength,maxlength"
>>>         bundle="alternate">
>>>         <arg0   key="sections.validate.title"/>
>>>         <arg1   key="${var:minlength}" name="minlength"
>>>           resource="false"/>
>>>         <arg2   key="${var:maxlength}" name="maxlength"
>>>           resource="false"/>
>>>         <var>
>>>           <var-name>maxlength</var-name>
>>>           <var-value>16</var-value>
>>>         </var>
>>>         <var>
>>>           <var-name>minlength</var-name>
>>>           <var-value>2</var-value>
>>>         </var>
>>>       </field>
>>>     </form>
>>>   </formset>
>>>
>>> Copied more or less from the struts-example app
>>>
>>> David Graham wrote:
>>>
>>>> What is your validation setup for that field and what are you entering
>>>> into it?  The struts-validator app seems to be working fine.
>>>>
>>>> David
>>>>
>>>>
>>>> --- Adam Hardy <ah...@cyberspaceroad.com> wrote:
>>>>
>>>>
>>>>> I shutdown and deleted my deploys and builds and recompiled and 
>>>>> redeployed everything, and I have the html:javascript static=true tag
>>>
>>>
>>> in
>>>
>>>>> the staticJavascript.jsp which I link into my page with the script
>>>
>>>
>>> tag,
>>>
>>>>> so I am pretty confident I don't have any old version of the static 
>>>>> javascript cached or generated anywhere. (I am on 1.1 final)
>>>>>
>>>>> The javascript is still giving me "must be min length" validation
>>>
>>>
>>> errors
>>>
>>>>> when I try to submit a blank field though.
>>>>>
>>>>> Should the static javascript taglib still be in a seperate file like
>>>
>>>
>>> in
>>>
>>>>> the example app?
>>>>>
>>>>> Adam
>>>>>
>>>>> David Graham wrote:
>>>>>
>>>>>
>>>>>> Client and server checks should be the same in 1.1 final.  If you
>>>>>> generated the static javascript and stored it in a file, make sure
>>>
>>>
>>> you
>>>
>>>>>> regenerate it after upgrading to 1.1 final.
>>>>>>
>>>>>> David
>>>>>
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>>>
>>>>
>>>>
>>>>
>>>> __________________________________
>>>> Do you Yahoo!?
>>>> SBC Yahoo! DSL - Now only $29.95 per month!
>>>> http://sbc.yahoo.com
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>>
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>
>>
>>
>>
>> __________________________________
>> Do you Yahoo!?
>> SBC Yahoo! DSL - Now only $29.95 per month!
>> http://sbc.yahoo.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 


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


Re: FieldChecks.validateMinLengths()

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
I'm sorry, it was my fault. I had forgotten to replace the 
validator-rules.xml with the new version.

David Graham wrote:
> Remove the <field bundle> attribute because that's not supported.  What
> text are you typing into the input box?
> 
> David
> 
> --- Adam Hardy <ah...@cyberspaceroad.com> wrote:
> 
>><formset>
>>     <form name="sectionForm">
>>       <field property="id"
>>         depends="integer">
>>         <arg0   key="sections.validate.id"/>
>>       </field>
>>       <field property="title"
>>         depends="minlength,maxlength"
>>         bundle="alternate">
>>         <arg0   key="sections.validate.title"/>
>>         <arg1   key="${var:minlength}" name="minlength"
>>           resource="false"/>
>>         <arg2   key="${var:maxlength}" name="maxlength"
>>           resource="false"/>
>>         <var>
>>           <var-name>maxlength</var-name>
>>           <var-value>16</var-value>
>>         </var>
>>         <var>
>>           <var-name>minlength</var-name>
>>           <var-value>2</var-value>
>>         </var>
>>       </field>
>>     </form>
>>   </formset>
>>
>>Copied more or less from the struts-example app
>>
>>David Graham wrote:
>>
>>>What is your validation setup for that field and what are you entering
>>>into it?  The struts-validator app seems to be working fine.
>>>
>>>David
>>>
>>>
>>>--- Adam Hardy <ah...@cyberspaceroad.com> wrote:
>>>
>>>
>>>>I shutdown and deleted my deploys and builds and recompiled and 
>>>>redeployed everything, and I have the html:javascript static=true tag
>>
>>in
>>
>>>>the staticJavascript.jsp which I link into my page with the script
>>
>>tag, 
>>
>>>>so I am pretty confident I don't have any old version of the static 
>>>>javascript cached or generated anywhere. (I am on 1.1 final)
>>>>
>>>>The javascript is still giving me "must be min length" validation
>>
>>errors
>>
>>>>when I try to submit a blank field though.
>>>>
>>>>Should the static javascript taglib still be in a seperate file like
>>
>>in 
>>
>>>>the example app?
>>>>
>>>>Adam
>>>>
>>>>David Graham wrote:
>>>>
>>>>
>>>>>Client and server checks should be the same in 1.1 final.  If you
>>>>>generated the static javascript and stored it in a file, make sure
>>
>>you
>>
>>>>>regenerate it after upgrading to 1.1 final.
>>>>>
>>>>>David
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>>
>>>
>>>
>>>
>>>__________________________________
>>>Do you Yahoo!?
>>>SBC Yahoo! DSL - Now only $29.95 per month!
>>>http://sbc.yahoo.com
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>
>>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
> 
> 
> 
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 


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


Re: FieldChecks.validateMinLengths()

Posted by David Graham <gr...@yahoo.com>.
Remove the <field bundle> attribute because that's not supported.  What
text are you typing into the input box?

David

--- Adam Hardy <ah...@cyberspaceroad.com> wrote:
> <formset>
>      <form name="sectionForm">
>        <field property="id"
>          depends="integer">
>          <arg0   key="sections.validate.id"/>
>        </field>
>        <field property="title"
>          depends="minlength,maxlength"
>          bundle="alternate">
>          <arg0   key="sections.validate.title"/>
>          <arg1   key="${var:minlength}" name="minlength"
>            resource="false"/>
>          <arg2   key="${var:maxlength}" name="maxlength"
>            resource="false"/>
>          <var>
>            <var-name>maxlength</var-name>
>            <var-value>16</var-value>
>          </var>
>          <var>
>            <var-name>minlength</var-name>
>            <var-value>2</var-value>
>          </var>
>        </field>
>      </form>
>    </formset>
> 
> Copied more or less from the struts-example app
> 
> David Graham wrote:
> > What is your validation setup for that field and what are you entering
> > into it?  The struts-validator app seems to be working fine.
> > 
> > David
> > 
> > 
> > --- Adam Hardy <ah...@cyberspaceroad.com> wrote:
> > 
> >>I shutdown and deleted my deploys and builds and recompiled and 
> >>redeployed everything, and I have the html:javascript static=true tag
> in
> >>
> >>the staticJavascript.jsp which I link into my page with the script
> tag, 
> >>so I am pretty confident I don't have any old version of the static 
> >>javascript cached or generated anywhere. (I am on 1.1 final)
> >>
> >>The javascript is still giving me "must be min length" validation
> errors
> >>
> >>when I try to submit a blank field though.
> >>
> >>Should the static javascript taglib still be in a seperate file like
> in 
> >>the example app?
> >>
> >>Adam
> >>
> >>David Graham wrote:
> >>
> >>>Client and server checks should be the same in 1.1 final.  If you
> >>>generated the static javascript and stored it in a file, make sure
> you
> >>>regenerate it after upgrading to 1.1 final.
> >>>
> >>>David
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >>
> > 
> > 
> > 
> > __________________________________
> > Do you Yahoo!?
> > SBC Yahoo! DSL - Now only $29.95 per month!
> > http://sbc.yahoo.com
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > 
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

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


Re: FieldChecks.validateMinLengths()

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
<formset>
     <form name="sectionForm">
       <field property="id"
         depends="integer">
         <arg0   key="sections.validate.id"/>
       </field>
       <field property="title"
         depends="minlength,maxlength"
         bundle="alternate">
         <arg0   key="sections.validate.title"/>
         <arg1   key="${var:minlength}" name="minlength"
           resource="false"/>
         <arg2   key="${var:maxlength}" name="maxlength"
           resource="false"/>
         <var>
           <var-name>maxlength</var-name>
           <var-value>16</var-value>
         </var>
         <var>
           <var-name>minlength</var-name>
           <var-value>2</var-value>
         </var>
       </field>
     </form>
   </formset>

Copied more or less from the struts-example app

David Graham wrote:
> What is your validation setup for that field and what are you entering
> into it?  The struts-validator app seems to be working fine.
> 
> David
> 
> 
> --- Adam Hardy <ah...@cyberspaceroad.com> wrote:
> 
>>I shutdown and deleted my deploys and builds and recompiled and 
>>redeployed everything, and I have the html:javascript static=true tag in
>>
>>the staticJavascript.jsp which I link into my page with the script tag, 
>>so I am pretty confident I don't have any old version of the static 
>>javascript cached or generated anywhere. (I am on 1.1 final)
>>
>>The javascript is still giving me "must be min length" validation errors
>>
>>when I try to submit a blank field though.
>>
>>Should the static javascript taglib still be in a seperate file like in 
>>the example app?
>>
>>Adam
>>
>>David Graham wrote:
>>
>>>Client and server checks should be the same in 1.1 final.  If you
>>>generated the static javascript and stored it in a file, make sure you
>>>regenerate it after upgrading to 1.1 final.
>>>
>>>David
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
> 
> 
> 
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 


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


Re: FieldChecks.validateMinLengths()

Posted by David Graham <gr...@yahoo.com>.
What is your validation setup for that field and what are you entering
into it?  The struts-validator app seems to be working fine.

David


--- Adam Hardy <ah...@cyberspaceroad.com> wrote:
> I shutdown and deleted my deploys and builds and recompiled and 
> redeployed everything, and I have the html:javascript static=true tag in
> 
> the staticJavascript.jsp which I link into my page with the script tag, 
> so I am pretty confident I don't have any old version of the static 
> javascript cached or generated anywhere. (I am on 1.1 final)
> 
> The javascript is still giving me "must be min length" validation errors
> 
> when I try to submit a blank field though.
> 
> Should the static javascript taglib still be in a seperate file like in 
> the example app?
> 
> Adam
> 
> David Graham wrote:
> > 
> > Client and server checks should be the same in 1.1 final.  If you
> > generated the static javascript and stored it in a file, make sure you
> > regenerate it after upgrading to 1.1 final.
> > 
> > David
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

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


Re: FieldChecks.validateMinLengths()

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
I shutdown and deleted my deploys and builds and recompiled and 
redeployed everything, and I have the html:javascript static=true tag in 
the staticJavascript.jsp which I link into my page with the script tag, 
so I am pretty confident I don't have any old version of the static 
javascript cached or generated anywhere. (I am on 1.1 final)

The javascript is still giving me "must be min length" validation errors 
when I try to submit a blank field though.

Should the static javascript taglib still be in a seperate file like in 
the example app?

Adam

David Graham wrote:
> 
> Client and server checks should be the same in 1.1 final.  If you
> generated the static javascript and stored it in a file, make sure you
> regenerate it after upgrading to 1.1 final.
> 
> David


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


Re: FieldChecks.validateMinLengths()

Posted by David Graham <gr...@yahoo.com>.
--- Adam Hardy <ah...@cyberspaceroad.com> wrote:
> Oh. I see. But the client-side validation does not behave this way.
> 
> I have just max and min length specified, and with javascript on, I 
> cannot submit if the field is blank.

Client and server checks should be the same in 1.1 final.  If you
generated the static javascript and stored it in a file, make sure you
regenerate it after upgrading to 1.1 final.

David

> 
> David Graham wrote:
> > This is actually a good thing :-).  Minlength will only fail if there
> is
> > some text in the control and it's less than the minimum length.  If
> you
> > want it to fail with no data you need to use the required validation. 
> By
> > separating these validations you can make a field optional and if the
> user
> > fills it in, it has to be more than minlength characters.
> > 
> > David
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

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


Re: FieldChecks.validateMinLengths()

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Oh. I see. But the client-side validation does not behave this way.

I have just max and min length specified, and with javascript on, I 
cannot submit if the field is blank.

David Graham wrote:
> This is actually a good thing :-).  Minlength will only fail if there is
> some text in the control and it's less than the minimum length.  If you
> want it to fail with no data you need to use the required validation.  By
> separating these validations you can make a field optional and if the user
> fills it in, it has to be more than minlength characters.
> 
> David


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


Re: FieldChecks.validateMinLengths()

Posted by David Graham <gr...@yahoo.com>.
--- Adam Hardy <ah...@cyberspaceroad.com> wrote:
> I started using struts validator. I just copied a bunch of stuff from 
> the struts example and started using that, and found that the minlength 
> validation actually returns true when the text field is blank.
> 
> This was my first attempt and I was trying to make sure I had got the 
> validator plug-in functioning correctly, so I actually spent a few hours
> 
> hunting down the reason why my blank field was passing validation even 
> though the minlength had been set to 1.
> 
> I discovered in the source code that this is normal behaviour - surely 
> that can't be the case? I would expect a blank field to fail validation 
> for minimum length. Or is this actually the case for reasons I'm not 
> aware of?

This is actually a good thing :-).  Minlength will only fail if there is
some text in the control and it's less than the minimum length.  If you
want it to fail with no data you need to use the required validation.  By
separating these validations you can make a field optional and if the user
fills it in, it has to be more than minlength characters.

David


> 
> Thanks
> Adam
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

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