struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bOOyah <boo...@nowhere.org>
Subject Re: AW: Field types in ActionForm/DynaForm
Date Wed, 07 Apr 2004 14:19:49 GMT
Andreas Solarik wrote:

> Hi Stjepan,
> 
> From what I understand, you will have a much easier time implementing
> validation for your forms if you use only strings. For example, receiving an
> integer value "ABCDEFG" might cause unexpected results.
> This is just my understanding. If theres more to it, them I'm happy to learn
> :)

That is my understanding too.

A simple example:

Imagine your form models a personnel record.

You have a field to hold an employee's Age.  Being a clever Struts 
designer you add a String (not an Integer) property to the Struts form 
bean to hold the employee's Age.

You have Struts Validation enabled.

If someone types "QWERTY" into that Age field on the HTML form, your 
Struts validation checks can trap it and the form will be forwarded back 
to the user with (perhaps) the Age field showing "QWERTY", highlighted 
with a "QWERTY is not a valid Age" error message.

But: if that property had been modeled originally as an Integer, then 
"QWERTY" would never make it into the form bean (because "QWERTY" cannot 
be converted to an Integer).  Which in turn means that when the form is 
re-displayed to show the user's error, the string "QWERTY" will not be 
seen in the Age field; the field would be empty.

Read-write Integer properties on form beans will work great until users 
enter bad data.  Read-only properties are unaffected of course.

I think I got that about right.

-- 
bOOyah


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


Mime
View raw message