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 03:28:52 GMT
Hubert,

I checked formDef and but I found out it is not what I want, here is the
reason, 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,

In formDef, you have to call
sampler = (TypeSampler) FormUtils.getFormValues(form,this,mapping,request);
to populate the form.

The problem of Struts form is it can't handle Locale data yet. So the field
in the bean can't be java.util.Date type, that's something bothers me.
Otherwise, Struts bean population is perfect.

Anyway, formDef is a great idea and it did save some configuration effort,
but it should be better if Struts bean populator can handle the locale
conversion automatically or by configuration.


OK, let me ask this way, how can I put two instances of the employee on the
same HTML form by using formDef?

If using Struts, I can put

<form-bean name="employeeFrom" type="
org.apache.struts.validator.DynaValidatorForm">
<form-property name="employee1" type="com.clear2pay.bph.bean.Employee"/>
<form-property name="employee2" type="com.clear2pay.bph.bean.Employee"/>
</form-bean>

<form ...>
<TABLE border=1 cellpadding=1 cellspacing=0>
<TR><TD>Name
<TD><input type="text" name="employee1.name <http://employee1.name>"
value="John Doe">
<TR><TD>Birth (DD MMM YYYY)
<TD><input type="text" name="employee1.birth" value="25 Sep 1950">
<TR><TD>Salary
<TD><input type="text" name="employee1.salary" value="40.000,50">
<TR><TD>Hire (DD.MM.YYYY)
<TD><input type="text" name="employee1.hireDate" value="15.02.1999">
</TABLE>

<TABLE border=1 cellpadding=1 cellspacing=0>
<TR><TD>Name
<TD><input type="text" name="employee2.name <http://employee2.name>"
value="John Doe">
<TR><TD>Birth (DD MMM YYYY)
<TD><input type="text" name="employee2.birth" value="25 Sep 1950">
<TR><TD>Salary
<TD><input type="text" name="employee2.salary" value="40.000,50">
<TR><TD>Hire (DD.MM.YYYY)
<TD><input type="text" name="employee2.hireDate" value="15.02.1999">
</TABLE>
</form>

Thanks.


On 11/4/05, Yujun Liang <yujun.liang@acm.org> wrote:
>
> Hubert,
>
> Good morning! ( Since I am sending it from Australia.)
>
> I am reading the document on formDef, it is such a nice plugin so why
> don't you incorporate it into Struts? It will make project much productive.
>
> Question for you,
>  Property type global converters
>
> Property type global converters are applied to all fields of a certain
> type. An example of this would be declaring the Date converter that's
> declared to handle Date fields.
>
>     <form-definition>
>         <global-converters>
>             <global-converter *for="property-type"
>                 target="java.util.Date"*
>                 param="MM/dd/yyyy"/>
>
>         </global-converters>
>     </form-definition>
>
> How can I convert an input from user to the Date field base on the Locale?
> I mean the locale is a varible during the session and conversion can handle multiple
locales.
>
> Sorry for asking this, but in a locale aware web application, the input is based on Locale
>
> For example, in US, enter 10/12/2005 it will be converted to October 12, 2005 and this
is December 10, 2005
> if the locale is Australia. How the global converter handles this?
>
>
> Thanks for your time.
>
> Regards
>
>
> On 11/3/05, Hubert Rabago <hrabago@gmail.com> wrote:
> >
> > FormDef works fine with Validator. For the most part they won't even
> > be aware of each other. There's no overlap in functionality and they
> > won't get in the way of one another.
> >
> > Hubert
> >
> > On 11/2/05, Yujun Liang < yujun.liang@acm.org> wrote:
> > > Hubert, your input is quite valuable. But I just wonder this suppose
> > to be
> > > handled by Struts itsself,
> > >
> > > You may also place a bean instance on your form, and use nested
> > property
> > > references. For example, you might have a "customer" bean on your
> > > ActionForm, and then refer to the property
> > > "customer.name <http://customer.name>< http://customer.name>"
> > > in your presentation page. This would correspond to the methods
> > > customer.getName() and customer.setName(String Name) on your customer
> > bean.
> > > See the Apache Struts Taglib Developer Guides for more about using the
> >
> > > nested syntax.
> > > http://struts.apache.org/struts-core/userGuide/building_controller.html#action_form_classes
> >
> > >
> > > Do you know whether this BeanDef works with Validator?
> > >
> > > Thanks.
> > >
> > > On 11/3/05, Hubert Rabago <hrabago@gmail.com> wrote:
> > > >
> > > > [ Oh, I missed my cue! :) ]
> > > >
> > > > If your form bean maps to a business object (and it sounds like it
> > > > does since you're using BeanUtils), you can try FormDef:
> > > > http://formdef.dev.java.net/
> > > >
> > > > You won't need to create a separate ActionForm class or manually
> > > > define your DynaActionForm, FormDef will configure it for you. You
> > > > can also specify how you want your fields formatted, including dates
> >
> > > > and numbers, and use FormDef's conversion methods in place of
> > > > BeanUtils.
> > > >
> > > > 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
>



--
Yujun Liang
yujun.liang@acm.org

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