struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jon.Ridgway" <Jon.Ridg...@upco.co.uk>
Subject RE: how to return errors from Model component
Date Fri, 06 Sep 2002 15:46:18 GMT
Hi All,

As Ted has pointed out you might also want to get your messages from the
resource bundle, in which case you would just use the key to key into the
bundle (I have had a number of clients recently however that wanted to use
LDAP/RDBMS as a central store for localized error messages - are there any
plans to extend Struts to support the storing of resources in a LDAP/RDBMS
store?)


Jon Ridgway


-----Original Message-----
From: Jon.Ridgway [mailto:Jon.Ridgway@upco.co.uk] 
Sent: 06 September 2002 16:41
To: 'Struts Users Mailing List'
Subject: RE: how to return errors from Model component

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 = exception.next();
	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 [mailto:dball@rhoworld.com] 
Sent: 06 September 2002 16:11
To: struts-user@jakarta.apache.org
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
include:

* 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:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>


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:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>


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:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message