Subject: Re: Problem w/ ActionForm Value Object mapper by Andrej Consulting
From: "Andrej" <[EMAIL PROTECTED]>
 ===
Roland,

sorry for replying late... I had to unsubscribe to the list (though I
replied to your Hotmail account :) ).

I'm not aware of any real problems with converting Integers using the
mapper. Can you please post the code (or pseudo-code) of your Form and VO?

In general, remember that the mapper is based on the method names. It will
try to match the getXYZ of the origin with the setXYZ of the destination...
this imposes a little discipline but is usually worth the effort. The
conversions are also performed based on the input/output types of the
methods... but if something goes wrong in the process, you should get either
a PropertyMapperException or a PropertyConversionException.

As regards to the way to actually perform the mapping, let's consider the
following:

MyForm:
getInteger(): String
setInteger(String):void

MyVO
getInteger():Integer
setInteger(Integer):void

* VO To Form (1)
MyVo vo = ... // a VO instance you got from your business processes
MyForm form = null;
form = (MyForm)VOToFormMapper.map(vo, new MyForm());

* VO To Form (2)
MyVo vo = ... // a VO instance you got from your business processes
MyForm form = new MyForm();
form = (MyForm)VOToFormMapper.map(vo, form);

Basically, you need to pass to the mapper an instance of the destination
(and not a null). When you instantiate your object doesn't really matter...
:)

For Form to VO, it should exactly the same BUT with FormToVOMapper (please
NOTE that it's VOtoFormMapper vs FormToVOMapper ... two DIFFERENT utility
classes).

vo = (MyVO)FormToVOMapper.map(form, new MyVO());

HTH

Andrej



"Mark Nichols" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]...
> Roland,
>
> I, too, was struggling with how best to transfer data between form-bean
and
> entity (value) objects. Like you I found bean utils copyProperties
> problematic since it didn't do conversions.
>
> Then I discovered Ted Husted's "Struts Catalog"
> (http://husted.com/about/scaffolding/catalog.htm), which has this bit of
> code in it:
>
> BeanUtils.populate(target,BeanUtils.describe(source)) ;
>
> This works better than copyProperties; however it doesn't work with
optional
> types, like Date.
>
> Worth a read if nothing else.
>
> mark
>
>
> >From: "Roland Chan" <[EMAIL PROTECTED]>
> >Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> >To: <[EMAIL PROTECTED]>
> >Subject: Problem w/ ActionForm Value Object mapper by Andrej Consulting
> >Date: Wed, 8 May 2002 12:42:48 -0400
> >
> >To prevent from doing the tedious task of manually copy properties from
> >value object to action forms and vice versa I looked to the the
> >ActionForm-Value Object mapper by Andrej Consulting
> >(http://www.mycgiserver.com/~andrej/technical/struts/struts.jsp) b/c it
> >had the benefit over the bean utils copyProperties method in that it
> >could do simple data type conversions.
> >
> >HOWEVER, I have run into a little bit of a snag and have yet to get a
> >response from Andrej.
> >Going from Form to VO is fine, however, I am experiencing problems with
> >VO to Form. It seems as though Integers are not being converted, and
> >there are frequent property copying to the wrong form properties. Has
> >anyone experienced this?
> >
> >Also, what is the best way to do a copy to form if the form already
> >exists? In the examples, Andrej uses this convention:
> >
> >form = VOToFormMapper.map(vo, new ExampleForm());
> >
> >but in my experience, to get your form correctly populated it has to be
> >this:
> >
> >form = VOToFormMapper.map(vo, form);
> >
> >Any thoughts? I'm also open to alternatives.
> >
> >Thanks in advance.
> >
> >
> >--
> >To unsubscribe, e-mail:
> ><mailto:[EMAIL PROTECTED]>
> >For additional commands, e-mail:
> ><mailto:[EMAIL PROTECTED]>
> >
>
>
> _________________________________________________________________
> MSN Photos is the easiest way to share and print your photos:
> http://photos.msn.com/support/worldwide.aspx
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>



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

Reply via email to