struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yujun Liang <yujun.li...@acm.org>
Subject Re: java.util.Date in Action Form Bean
Date Wed, 09 Nov 2005 05:44:18 GMT
Hubert,

You made a very good point. Thanks for your patient explanation, that's
exactly the problem I am facing, all int fields are initialized to 0.
Probably even I want to use this feature, I need design a DTO for the form,
and put all String or boolean values as properties.

At beginning I just wanted to re-use some assets, but it turns out some idea
is not feasible, even it is doable.

Thanks.

On 11/9/05, Hubert Rabago <hrabago@gmail.com> wrote:
>
> On 11/8/05, Yujun Liang <yujun.liang@acm.org> 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: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


--
Yujun Liang
yujun.liang@acm.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message