You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Michael Jouravlev <jm...@gmail.com> on 2006/08/03 00:05:27 UTC

Re: FormDef

On 7/20/06, Hubert Rabago <hr...@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? 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?

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


Re: FormDef

Posted by Hubert Rabago <hr...@gmail.com>.
On 8/2/06, Michael Jouravlev <jm...@gmail.com> wrote:
> On 7/20/06, Hubert Rabago <hr...@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