struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Colin Hawkett" <co...@morpheus.co.uk>
Subject mapping to domain objects
Date Wed, 18 Dec 2002 09:41:35 GMT
Hi,

	I had previously been using struts 1.0, and have started a project using
1.1 - in 1.0 the method I used to map forms to domain objects (By domain
object I mean value object - representing the problem domain e.g. User,
Account, Bank etc.) was to create an action form with the domain object as
an attribute.  I would then create special setters and getters in the domain
object to handle the different types coming in as Strings - e.g.

public void setDateString(String date);
pubic String getDateString();

and also use the nested library to traverse the domain hierarchy (e.g. loop
through a list of accounts in a bank domain object).

Basically I don't like this method because it corrupts all of the domain
objects with methods that are specifically for the presentation layer, and I
couldn't easily validate the incoming values without creating an ActionError
list in the domain object and pulling this out when I hit the validator.
Never mind - lesson learned.  I really did like the nested tags though.

Now that struts 1.1 is on the table I am wondering what I can do to make
this better.  I like the DynaValidator but this appears to only be useful
for static forms (ones that aren't changing depending on the data).

I've been looking at the decalrative exception structure - but I can't quite
make out whether these exceptions can only be caught from the Action or also
from the form associated with the action.  Thats probably one for me to
check out although I can't see it mentioned anywhere.  I was thinking this
might be a good way to handle the problem of domain validating by doign the
validation in the setters and throwing exceptions rather than doing it in
the validate() method.

The only other method I can really see is to produce a wrapper around my
domain objects specifically for the purpose of providing String
setter/getter interfaces so I don't get number format errors on my setters
trying to convert to the actual attribute types.

I guess the main aim of this post was to see if there is a way of doing this
that anybody has found elegant.  I am probably missing something - but what
I am really looking for is a way to map form strings to domain attribute
types directly trapping any format errors in the process.  Any pointers?
Thanks in advance

Colin

Colin Hawkett
Technical Architect
Morpheus - eBusiness Solutions
Morpheus Limited, Gibbs House, Kennel Ride, Ascot, Berkshire, SL5 7NT
Email: colin@morpheus.co.uk
Tel: 01344 891621; Fax: 01344 891620
Web: http://www.morpheus.co.uk

*Winner of the IBM Solution Excellence Award for e-Commerce 2001*
*Solution Provider of the Month - Channel 2002 Magazine*
*Investor in People*




****************************************************************************

This email and any files transmitted with it contain information that may be
confidential or privileged, and are intended solely for the use of the
individual or entity to whom they are addressed. If you are not the intended
recipient any disclosure, copying, distribution or use of the information is
prohibited. If you have received this email in error, please notify me by
return email immediately. Any opinions expressed are those of the author,
not of Morpheus Limited.


This message has been checked for all known viruses by UUNET delivered 
through the MessageLabs Virus Control Centre.

****************************************************************************

--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message