That is probably the issue.  Validation occurs *after* the value is
copied into the form bean from the request.  Here's the basic sequence
of events:

  1) Your request comes in with parameter foo=notafloat
  2) The Struts framework attempts to convert "notafloat" to a float
and assign it to your form bean
  3) Step (2) fails (very quietly -- "notafloat" could not be
converted, so the value was left as the default)
  4) The validator framework then attempts to validate the values
contained in the form bean.  The value of the 'foo' property is of
type 'float', which (obviously) validates as a float.

The general recommendation is that all FormBean properties should be
Strings.  This way, no matter what the user enters, it will be stored
in the FormBean, and can therefore be re-displayed if there is a
validation error.  Personally, I think it would make a lot more sense
to validate the parameters on the request *before* attempting to
populate the form bean, allowing a strongly typed form bean.  I
believe this is the approach taken by Java ServerFaces and other
frameworks newer than Struts.

-- Jeff

On 6/20/05, Dornback, Ken <[EMAIL PROTECTED]> wrote:
> It is float in the formbean.
> 
> -----Original Message-----
> From: Jeff Beal [mailto:[EMAIL PROTECTED]
> Sent: Monday, June 20, 2005 12:11 PM
> To: Struts Users Mailing List
> Subject: Re: Float Validation not working
> 
> On the form bean, what is the type of the field?  (String, float, or
> Float)
> 
> On 6/20/05, Dornback, Ken <[EMAIL PROTECTED]> wrote:
> > I have to validate a float. I can type anything or nothing in and
> never
> > see a validation problem when I set the depends attribute to
> "required,
> > float".  The field just ends up 0 upon save.
> >
> > If I add a floatRange, it will complain at least complain if a number
> is
> > outside of the range, but I don't need to enforce a range, since all
> > floats are valid.  Setting the validation to integer works, but I
> don't
> > want that.
> >
> >
> >
> > Thanks.
> >
> >
> >
> >
> >
> 
> ---------------------------------------------------------------------
> 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