struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Barry <paul.ba...@nyu.edu>
Subject Re: validator integer required
Date Thu, 01 Apr 2004 23:01:14 GMT
validate is true.  I wrote my own "greaterThan" validation to make sure 
the property is greater than 0, which seems to work.  I haven't looked 
at how the validator works at all, but it seems that it checks the form 
bean, not the request parameters, to validate the values.  Is that the 
case?  If that is true, if I had a String property where I gave it some 
default value in my bean, like String property = "default", when someone 
submits a form the validation would always pass because the property of 
the ActionForm is not null, regardless of whether or not the was a 
"property" request parameter.  This is example is stupid, because you 
would never have a default value on a require property, but the point is 
this may explain the behavior I am seeing with the int property.  The 
int in the form is not blank or null, because it is 0 (primitives can't 
be null), so therefore it passes the required validation.

The value we are talking about should match up to an oracle sequence 
generated int, so it always should be an int, which is why I made the 
ActionForm property an int.  I guess I could make it a String property 
in the ActionForm and just use the "integer" validation to make sure it 
is an int, even though the ActionForm property is a String?  Would that 
work?

Joe Hertz wrote:

> Well, it's not the *expected* behavior.
> 
> First thing -- I'd make id a String. The validator parses String properties. 
> Not having looked into the validator code myself, I suppose "required" 
> *could* work for a non string property, but I sure wouldn't try it with a 
> primative like int. Integer might have better results, but I'm speculating. 
> 
> Just make id a String in the form and be done with it.
> 
> Aside from that, std questions about validator setup:
> 
> Is validate="true" on your ActionMapping?
> 
> Are we talking about a ValidatorForm or a ValidatorActionForm? With the 
> letter, you validate the Mapping name. with the former you validate the form 
> name?
> 
> HTH,
> 
> Joe
> 
> 
>>-----Original Message-----
>>From: Paul Barry [mailto:paul.barry@nyu.edu] 
>>Sent: Thursday, April 01, 2004 5:38 PM
>>To: user@struts.apache.org
>>Subject: validator integer required
>>
>>
>>I have an ActionForm with an int property called id.  If I use the 
>>validator \"required\" validation, it always passes the 
>>validation, even 
>>if there is no request parameter called id.  Is this is correct 
>>behavior, or am I doing something wrong?
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

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


Mime
View raw message