You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Stjepan Brbot <st...@ht.hr> on 2004/04/07 15:31:03 UTC

Field types in ActionForm/DynaForm

Hi all,

Does STRUTS ActionForm/DynaForm have to consist only of String object
fields!? Although I saw this strong recommendation in some books and
articles on Internet (since all parameters in Request are Strings) I use
Action and DynaForms with java.lang.Integer fields and everything works
fine! (Integer fields are very convenient when one deals with EJBs where IDs
are of Integer type.) It seems that STRUTS framework automatically converts
Strings from request into defined fields types of Form. Why should one use
only String fields and avoid Form fields other than Strings?

Stjepan Brbot


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


Re: AW: Field types in ActionForm/DynaForm

Posted by bOOyah <bo...@nowhere.org>.
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


AW: Field types in ActionForm/DynaForm

Posted by Andreas Solarik <a....@gesig.at>.
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
:)

Andreas

-----Ursprüngliche Nachricht-----
Von: James Mitchell [mailto:jmitchell@apache.org]
Gesendet: Mittwoch, 07. April 2004 15:34
An: Struts Developers List
Cc: Struts Users Mailing List
Betreff: Re: Field types in ActionForm/DynaForm


This needs to be on user@struts.apache.org.


--
James Mitchell
Software Engineer / Open Source Evangelist
EdgeTech, Inc.
678.910.8017
AIM: jmitchtx
MSN: jmitchell@apache.org
Yahoo IM:jmitchtx@yahoo.com



----- Original Message -----
From: "Stjepan Brbot" <st...@ht.hr>
To: "STRUTS - Developer" <st...@jakarta.apache.org>
Sent: Wednesday, April 07, 2004 9:31 AM
Subject: Field types in ActionForm/DynaForm


> Hi all,
>
> Does STRUTS ActionForm/DynaForm have to consist only of String object
> fields!? Although I saw this strong recommendation in some books and
> articles on Internet (since all parameters in Request are Strings) I use
> Action and DynaForms with java.lang.Integer fields and everything works
> fine! (Integer fields are very convenient when one deals with EJBs where
IDs
> are of Integer type.) It seems that STRUTS framework automatically
converts
> Strings from request into defined fields types of Form. Why should one use
> only String fields and avoid Form fields other than Strings?
>
> Stjepan Brbot
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>



---------------------------------------------------------------------
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


Re: Field types in ActionForm/DynaForm

Posted by James Mitchell <jm...@apache.org>.
This needs to be on user@struts.apache.org.


--
James Mitchell
Software Engineer / Open Source Evangelist
EdgeTech, Inc.
678.910.8017
AIM: jmitchtx
MSN: jmitchell@apache.org
Yahoo IM:jmitchtx@yahoo.com



----- Original Message -----
From: "Stjepan Brbot" <st...@ht.hr>
To: "STRUTS - Developer" <st...@jakarta.apache.org>
Sent: Wednesday, April 07, 2004 9:31 AM
Subject: Field types in ActionForm/DynaForm


> Hi all,
>
> Does STRUTS ActionForm/DynaForm have to consist only of String object
> fields!? Although I saw this strong recommendation in some books and
> articles on Internet (since all parameters in Request are Strings) I use
> Action and DynaForms with java.lang.Integer fields and everything works
> fine! (Integer fields are very convenient when one deals with EJBs where
IDs
> are of Integer type.) It seems that STRUTS framework automatically
converts
> Strings from request into defined fields types of Form. Why should one use
> only String fields and avoid Form fields other than Strings?
>
> Stjepan Brbot
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>



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


Re: Field types in ActionForm/DynaForm

Posted by James Mitchell <jm...@apache.org>.
This needs to be on user@struts.apache.org.


--
James Mitchell
Software Engineer / Open Source Evangelist
EdgeTech, Inc.
678.910.8017
AIM: jmitchtx
MSN: jmitchell@apache.org
Yahoo IM:jmitchtx@yahoo.com



----- Original Message -----
From: "Stjepan Brbot" <st...@ht.hr>
To: "STRUTS - Developer" <st...@jakarta.apache.org>
Sent: Wednesday, April 07, 2004 9:31 AM
Subject: Field types in ActionForm/DynaForm


> Hi all,
>
> Does STRUTS ActionForm/DynaForm have to consist only of String object
> fields!? Although I saw this strong recommendation in some books and
> articles on Internet (since all parameters in Request are Strings) I use
> Action and DynaForms with java.lang.Integer fields and everything works
> fine! (Integer fields are very convenient when one deals with EJBs where
IDs
> are of Integer type.) It seems that STRUTS framework automatically
converts
> Strings from request into defined fields types of Form. Why should one use
> only String fields and avoid Form fields other than Strings?
>
> Stjepan Brbot
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>



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