You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Wendy Smoak <We...@asu.edu> on 2002/10/14 21:31:20 UTC

ActionForm & Value Objects

I have an ActionForm (ContactForm) object in scope, and _also_ a ContactImpl
value object that pretty much mirrors the get/set methods in the
ContactForm.

I'm using the BeanUtils.copyProperties method to move the properties back
and forth, but I'm confused as to when each of the objects should have
priority.  (IOW, when to change a property in which one.)

I found myself using:
<bean:write name="contact" property="prospectId"/>

and then wondering why the property didn't have the correct value.

So... I think the rule is that in the JSP associated with the ActionForm,
you should be using the instance of the form as the "bean" for any extra
display work that must be done outside of the <html:text>, etc. tags that go
inside the <html:form> tags.

And then the Value Object is only used at the very beginning to populate the
form the first time for editing, and at the last minute before it gets sent
off to the DAO to be persisted.

Is that right?

Thanks in advance for helping me get this straight,

-- 
Wendy Smoak
http://sourceforge.net/projects/unidbtags 

Re: ActionForm & Value Objects

Posted by Eddie Bush <ek...@swbell.net>.
Wendy Smoak wrote:

>I have an ActionForm (ContactForm) object in scope, and _also_ a ContactImpl
>value object that pretty much mirrors the get/set methods in the
>ContactForm.
>
>I'm using the BeanUtils.copyProperties method to move the properties back
>and forth, but I'm confused as to when each of the objects should have
>priority.  (IOW, when to change a property in which one.)
>
>I found myself using:
><bean:write name="contact" property="prospectId"/>
>
>and then wondering why the property didn't have the correct value.
>
>So... I think the rule is that in the JSP associated with the ActionForm,
>you should be using the instance of the form as the "bean" for any extra
>display work that must be done outside of the <html:text>, etc. tags that go
>inside the <html:form> tags.
>
>And then the Value Object is only used at the very beginning to populate the
>form the first time for editing, and at the last minute before it gets sent
>off to the DAO to be persisted.
>
>Is that right?
>
Sounds good!

>Thanks in advance for helping me get this straight,
>
Your goal in doing the copy in the first place is to minimize hitting 
the database, and present the user with the exact incorrect values they 
entered - and not have to worry about those values making it into your 
database.  So, yes, there are two hits here:  1 - retrieve the data for 
editing; 2 - update the data (once the user has signaled they are done 
editing and wish their changes to be persisted)

Sounds good :-)

-- 
Eddie Bush




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>