(inline)

-----Original Message-----
From: Michael Jouravlev [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 20, 2006 6:16 PM
To: Struts Users Mailing List
Subject: Re: FormDef

Um, by nested beans I mean a bean which is a property of ActionForm
like Employee, not a bean which is a property of a bean which is a
property of an ActionForm, like Address. I guess there is a
discrepancy in terminology here ;-)

What I mean is this (taken from
http://www.rabago.net/struts/formdef/manual.htm):

"To declare a form bean using FormDef, simple add a <form> entry in
the configuration file, provide the name for your form bean, and the
name of the class from which the form bean will be patterned after.
... When the plugin gets executed, it will create a DynaActionForm
containing String fields for each property of MyBean.

To me MyBean is nested within a DynaActionForm. If this is not a
proper term, what do you call it? Calling it just a property will do a
disservice (I think so) because it is not a primitive type.

Actually, with FormDef, it will be a primitive type (err, String, actually).
What FormDef generates is a String field for each field of MyBean.

Okay, let's make sure we're talking about the same thing.
If I were to just use struts-config.xml to define my forms, here's two
ways I can do it.

Here's a non-nested approach (Approach 1):

<form-bean name="myForm" type="o.a.s.DynaActionForm>
 <form-property name="field1" type="java.lang.String"/>
 <form-property name="field2" type="java.lang.String"/>
</form-bean>

<html:form action="..">
 <html:text property="field1"/>
 <html:text property="field2"/>
</html:form>

BeanUtils.copyProperties(myForm, myBean);


Here's my interpretation of a nested approach (Approach 2):

<form-bean name="myForm" type="o.a.s.DynaActionForm>
 <form-property name="myBean" type="MyBean"/>
</form-bean>

<html:form action="..">
 <html:text property="myBean.field1"/>
 <html:text property="myBean.field2"/>
</html:form>

myBean = ((DynaActionForm) myForm).get("myBean");


FormDef use Approach 1.

So when converters and validators are executed? Is it correct that
when I call  FormUtils.setFormValues() then output converter is
executed (uh, do you have output converters?), and when I call
FormUtils.getFormValues() then input converters and validators are
executed? Validation or conversion is not executed automatically or at
least can be turned off?


Yes, there are output converters.  Validation would typically be
through Commons Validator (like most dyna forms).  Conversion happens
based on convention but can be configured by the user.


Hubert


On 7/20/06, Hubert Rabago <[EMAIL PROTECTED]> wrote:
> (was: Is there any direct link between model and view in struts..)
>
> On 7/20/06, Michael Jouravlev <[EMAIL PROTECTED]> wrote:
> Another library,
> > FormDef, can build a dynaform based on properties of
nested business
> > object
>
> Hey Michael,
>
> Just thought I'd set the record straight.
> FormDef does not require nor enforce nested beans.
>
> public class Employee {
>     public String getName() { return name; }
>     public void setName(String name) { this.name = name; }
>
>     public Date getHireDate() { return hireDate; }
>     public void setHireDate(Date hireDate) { this.hireDate
= hireDate; }
>
>     public int getZipCode() { return zipCode; }
>     public void setZipCode(int zipCode) { this.zipCode = zipCode; }
> }
>
>   ... plus ...
>
> <form name="employeeForm" beanType="Employee"/>
>
>
>   ... equals ...
>
>
> <form-bean name="employeeForm"
type="org.apache.struts.action.DynaActionForm">
>     <form-property name="name" type="java.lang.String"/>
>     <form-property name="hireDate" type="java.lang.String"/>
>     <form-property name="zipCode" type="java.lang.String"/>
> </form-bean>
>
> You're still using traditional ActionForms, and you still
need to copy
> to and from the form bean and business object (using BeanUtils or
> FormDef's own methods).
>
> So, your form still looks the same way:
>
> <html:text property="name"/>
> <html:text property="hireDate"/>
> <html:text property="zipCode"/>
>
> 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"/>
>
>
> Hubert
>

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

Reply via email to