I've been playing #3 (Just included the value objects in the form) and run
into one of those things that probably makes people break into tears.

I have int types in the value object... And since they cannot be null, when
the form is prepopulated or repopulated they appear as "0" instead of being
blank or what the user entered.  Sad.

-jdr

On 5/28/03 9:53 PM, "Andrew Hill" <[EMAIL PROTECTED]> wrote:

> 2 & 3 generally end in tears. They sound nice, but when you get down to the
> fiddly bits you will find it more problematic than you expect.
> 
> As you mention, the action form is very much a view object. For a start
> everything in the actionForm will be strings, while your business object
> probably will not be. Secondly, while there is considerable overlap between
> your value object and your form, you will find (especially as your ui gets
> more complex) that the correlation is not 1 to 1 and that you are exerting a
> lot of effort to try and keep the two the same.
> 
> Approach 3 is probably the worst - unless its for read only display - in
> that if the user enters a value that doesnt convert to your value objects
> property type you will want to redisplay the offending value string the same
> as the user typed it for them to correct it.
> 
> Your best bet is to use approach 1. You may be interested to note that the
> BeanUtils class does have some methods that can make life simpler for you -
> copying property values and doing type conversions automatically (if I
> recall correctly).
> 
> (Actually I generally copy the properties the 'hard' way, one by one in my
> action)
> 
> -----Original Message-----
> From: Jordan Reed [mailto:[EMAIL PROTECTED]
> Sent: Thursday, 29 May 2003 12:29
> To: Struts Users Mailing List
> Subject: Populating Value Objects for the Business Tier
> 
> 
> All,
> 
> I'm on a team that's trying to decided on a best practice for passing on
> populating our value objects that get passed to our business layer.  We
> currently have three techniques we've though up and I'm wonderful if anyone
> has a strong opinion on which one may be the "best" and why.
> 
> The basic problem is that the user enters information into a form.  The form
> is a presentation object, and should not be passed to the business layer.
> So it's information needs to be in a presentation-agnostic interface before
> being passed to the data layer.
> 
> 1) Have the action class copy information from the form to a value object.
> Have a view helper copy information from the value object into the form (for
> pre-population)
> 
> 2) Have the form implement a value-object-like interface.  The business
> layer accepts objects with these business interfaces.  This way it is
> possible to pass the form objects to the business layer without the business
> layer knowing that they are presentation objects.
> 
> 3) Have the form simply include value objects as properties.  Then use the
> nested taglibs to populate the value objects.  This way the Action can just
> pull the value object off directly and pass to the business layer.  A view
> helper can just set the value object on the form.
> 
> 
> -jdr


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

Reply via email to