You have a variety of options, some of which I'll introduce but I
won't have time right now to go deeply into details.  However, if you
ask a specific questions (in this or in new threads), there's a good
chance someone will reply.  [As others would expect, I'd be hawking my
own project, FormDef.]

First is what Michael already mentioned - you can nest your POJO in a
form bean.  It could be something like:

<form-bean name="myForm"
           type="org.apache.struts.validator.DynaValidatorForm">
      <form-property name="pojo" type="com.dto.MyPojo"/>
</form-bean>

Let's say MyPojo had fields like "firstName", "lastName", "salary",
and "hireDate".  Your form will have fields like "pojo.firstName" and
"pojo.hireDate".

Another is to use your bean directly.  Underneath, Struts will wrap it
in a BeanValidatorForm (which uses BeanUtils' WrapDynaBean):

<form-bean name="myForm"
           type="com.dto.MyPojo"/>

It was recently discovered, though, that WrapDynaBean is not
serializable, so you should only use these beans in request scope.

Depending on how you set these up, it can work directly on your pojos,
so you wouldn't have to worry about copying values to/from your beans.
 However, you'd lose some of the usability features of struts, such as
allowing the user to edit mistakes on forms.  Dates can get tricky,
too.

Another option is to use look at projects such as StrutsLive (which
also uses nesting) or FormDef (which defines your bean for you). 
These are both on the java.net site.  You can find out more about
StrutsLive in https://strutslive.dev.java.net/.  FormDef is on
https://formdef.dev.java.net/.

FormDef allows you to automatically declare a dynamic ActionForm (see
http://struts.apache.org/userGuide/building_controller.html#dyna_action_form_classes
) based on your POJO.  So with a config like:

<form name="myForm" beanType="com.dto.MyPojo"/>

You'd get:

<form-bean name="myForm" 
    type="org.apache.struts.action.DynaActionForm">
    <form-property name="firstName" type="java.lang.String"/>
    <form-property name="lastName" type="java.lang.String"/>
    <form-property name="salary" type="java.lang.String"/>
    <form-property name="hireDate" type="java.lang.String"/>
</form-bean>

(you can add fields to handle add'l form elements like buttons)

There's nothing magical about the bean that's generated.  It's just
what you'd get if you had declared it yourself in struts-config,
except you didn't have to write it yourself.  You can use BeanUtils as
you would for other form beans.  Struts wouldn't know the difference
between a FormDef generated bean and one you declared yourself. 
FormDef has other features for formatting/conversion that you can use,
but those are optional.

Hubert


On 8/9/05, Ed Griebel <[EMAIL PROTECTED]> wrote:
> Mick-
> 
> You can use dynaforms and declare them in your struts-config.xml and
> as mentioned use BeanUtils.copyProperties to move data between them.
> 
> Also, there has been mentioned on this list a library/tool which groks
> your DTOs and generates formBeans, but I can't recall now what it's
> called.
> 
> -ed
> 
> On 8/9/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > Also, remember that your ActionForm properties all should be strings,
> > while your DTOs should be typed.  You can use BeanUtils.copyProperties to
> > do the conversion.
> >
> > Say, does anyone have a dynamic AOP-style ActionFormProxy class that you
> > could use to dynamically decorate a DTO?  it would make ints, longs, etc.
> > on the DTO look like Strings at the ActionForm layer, but you could get
> > the DTO itself to pass to the business layer.  Dates are a challenge,
> > though, because of the variety of formats.
> >
> > -- Bill
> >

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

Reply via email to