struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jon.Ridgway" <>
Subject RE: how to return errors from Model component
Date Fri, 06 Sep 2002 15:40:34 GMT
Hi Donald,

The approach I have used is to define a base exception that contains a map
of error messages. Have your business exceptions extend this. In the struts
action class catch the exception and morph them into ActionErrors, ie

ActionErrors errors = new ActionErrors ();

while (exception.hasNext ())
	key =;
	msg = exception.get(key)

	errors.add (key, new ActionError (key, msg));

saveErrors (errors);

You could add this logic into a utility singleton and away you go...

Jon Ridgway

-----Original Message-----
From: Donald Ball [] 
Sent: 06 September 2002 16:11
Subject: how to return errors from Model component

Hey guys, I have an MVC-type question. My View captures data from the user
and sends it to the Controller, which validates and massages it and uses it
to configure the Model and tell the Model to do something. Based on the
something, the Controller sends another View to the client. So far so good.

What happens when something, or rather, somethings go wrong when the Model
is doing its work? How should the Model communicate this to the Controller
in a way that doesn't violate the seperation of concerns? Currently, my
Model creates a struts ActionErrors object and puts the error messages into
it and returns it to the Controller. This strikes me as a bad design choice
because the Model object shouldn't have any notion of the environment in
which it lives. However, I'm unsure what the best practice is. Choices

* Tossing an exception - but I would like to be able to send multiple
errors at the same time

* Return a List or array of String error messages - but then my messages
are hard-coded into the application, making i18n painful. I could make the
Strings returned be keys into the ApplicationResources properties file, but
then how do I attach parameters for messages that need them?

* Return, oh, a SortedMap of error messages, where the keys are the error
message keys, sorted in order of occurance, and the values are Lists of
parameters for the error messages - but this seems awfully convoluted.

Any suggestions?

- donald

To unsubscribe, e-mail:
For additional commands, e-mail:

The contents of this email are intended only for the named addressees and
may contain confidential and/or privileged material. If received in error
please contact UPCO on +44 (0) 113 201 0600 and then delete the entire
e-mail from your system. Unauthorised review, distribution, disclosure or
other use of this information could constitute a breach of confidence. Your
co-operation in this matter is greatly appreciated. 

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message