struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hubert Rabago" <hrab...@gmail.com>
Subject Re: FormDef
Date Wed, 02 Aug 2006 22:48:47 GMT
On 8/2/06, Michael Jouravlev <jmikus@gmail.com> wrote:
> On 7/20/06, Hubert Rabago <hrabago@gmail.com> wrote:
> > FormDef support nested beans, and nested collections of beans.  If you
> > had a nested Address object, your form would look like:
> >
> > <html:text property="name"/>
> > <html:text property="hireDate"/>
> > <html:text property="address.zipCode"/>
>
> In your example Address is nested within ActionForm, right?

No.  What happens is an ActionForm is nested within an ActionForm.

((DynaBean) form).get("address") will return another DynaBean.

What if I
> have an object like Person having Address as its member. All
> properties are strongly-typed so I do not want to expose them for I/O,
> instead I want to have autogenerated ActionForm fields so that I could
> redisplay them on error. Say I do not nest Persion inside ActionForm.
> Can I still somehow have a string property inside my ActionForm that
> corresponds to Person.Address? Can this property be autogenerated?

This is how FormDef works.  Of course, you'll have to tell FormDef
about the address form, but that's very easy:

    <form name="addressForm"
        beanType="my.package.Address"/>

    <form name="employeeForm"
        beanType="my.package.Person">

        <!-- specify that our address field should use addressForm -->
        <field property="address" formName="addressForm"/>
    </form>

FormUtils.getFormValues() and setFormValues() takes care of handling
the nested objects, instantiating them as needed.

As you can imagine, they can go multiple levels, all nesting
Stringified versions of your business objects.  In one of my sample
apps, I have a "companyForm" with an "addressForm" and a collection of
"employeeForm" objects, with each employee having its own
"addressForm" nested form.

Hubert

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


Mime
View raw message