On 11/8/05, Yujun Liang <[EMAIL PROTECTED]> wrote:
> in Struts, you can define
> <form-bean name="instructionForm"
             type="org.apache.struts.validator.DynaValidatorForm">
>   <form-property name="instruction" 
> type="com.clear2pay.bph.bean.Instruction"/>
> </form-bean>
>
> and you can just call,
>
> bean = ((DynaActionForm) form).get(pageName);
> in this case pageName = "instruction";
>
> and Struts automatically populate a
> com.clear2pay.bph.bean.Instructionobject in the form,


I feel I have to explain something about Struts form beans.

It is not recommended that you use fields other than String and
boolean in your form beans.  The form bean is where the request
parameters are stored before your fields are even validated.  If
validation fails, you'd ideally want to preserve what the user typed
in so s/he can correct his/her input.

For instance, if the user typed in "1q3" in field that's meant to hold
a numeric value, the field will be marked invalid and the form will be
shown to the user again.  If the form bean used a String for this
property, the user will see the "1q3" value on the input control.  If
the form bean used an int for the property, the attempt to populate
that field with "1q3" would fail and the user would see "0" instead. 
The same thing applies to date fields.  I don't even know what will
happen if the user typed in "35 Se[ 2005" on a field that's declared
as java.util.Date.  The best approach is to use String fields, so the
user's input is preserved, and in the case of user errors, they will
be able to edit the values they typed in instead of starting over
again.

Of course, each application has its own set of circumstances, so this
may not be an issue for you.  If you're still interested in checking
out FormDef, though, take a look at
http://www.rabago.net/struts/formdef/dev/nested.htm .  This page
describes FormDef's support for nested beans with the latest dev
builds..

Hubert

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

Reply via email to