On Tue, 9 Apr 2002, Konstantin Priblouda wrote:

> Date: Tue, 9 Apr 2002 08:15:03 -0700 (PDT)
> From: Konstantin Priblouda <[EMAIL PROTECTED]>
> Reply-To: Struts Developers List <[EMAIL PROTECTED]>
> To: Struts Developers List <[EMAIL PROTECTED]>,
>      [EMAIL PROTECTED]
> Subject: RE: Is FormBean mandatory???
>
> --- Matt Raible <[EMAIL PROTECTED]> wrote:
> > Web forms can only handle Strings and booleans - so
> > if your value
> > objects have Dates or Integers, get ready for some
> > fun!
>
> Integers are completely OK, floats depend on sanity of
> web users. ( imagine some bank clerk who is used
> to enter dots to separate 000... )
>

Using int or Integer properties in a form bean misses the whole reason for
its existence -- to reproduce the user's input in case they made a
mistake.

Consider that you've got an input field called "size", which (in your
business logic should really be an integer).  Assume for a moment that you
try to use an "int" or "Integer" property in the form bean, so that the
conversion happens as the form bean properties get populated.  Now, assume
that the user mis-types "1a3" instead of "123" into this field.

Using an int field, you get an ugly exception when the form bean
properties are populated -- and any properties that haven't been populated
yet have errors.

Using a String field, you get the ability to validate the input, produce a
nice error message, and (most importantly to meet users expectations)
redisplay the input field with the incorrect value that he or she did
enter, so that they can fix it.  Any user who has ever used a GUI app is
going to expect this behavior in a web app.

The form bean is part of the VIEW layer in an MVC architecture, not the
MODEL layer.  It's sole purpose in life is to represent the server-side
state of the last set of inputs to a particular form (even if they are not
valid).  Conversion into value objects (or directly to the database,
depending on how you have your business logic set up) should be done by a
"save" type action, after the form fields have been validated.

> IMHO, struts shall behave more beany/reflection- with
> possibility to set property editors for a bean.
>
> ( now I'm doing blasphemy: like webwork does :) )
>

It turns out that property editors have technical problems that have been
discussed before (check the mail archives for details).  However, you
should check out the recent changes to ConvertUtils in the
commons-beanutils package), which let you plug in your own String->Object
converters.  This is available in the Struts 1.1 beta, and will also be
available in the 1.1 final release.

> regards,
>
>
> =====
> Konstantin Priblouda ( ko5tik )    Freelance Software developer
> < http://www.pribluda.de > < play java games -> http://www.yook.de >
> < render charts online -> http://www.pribluda.de/povray/ >
>

Craig


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

Reply via email to