Emmanouil Batsis on 14/04/06 08:56, wrote:
I'm very interested to hear about how do you guys handle business-tier-dependent validation errors in a struts+EJB application. For example, suppose a user tries to create an account with a username that already exists (maybe a poor example but you get the point), but you can only figure this out in the business tier if you want to avoid multiple RMI calls. Any best practices or examples would be very much appreciated. The only things that i can think of at the moment is subclassing EJBException (no clue if that would really work) or coming up with a generic DTO as the business response (to carry error information if appropriate).

In the presentation layer, there are fundamentally two types of failure - recoverable and unrecoverable.

Recoverable errors are to do with business rules, bad data, validation, and so forth and the user must be informed that they cannot achieve what they want to in the way they want to. Essentially it is normally sufficient to flag this up as a notification on the page where the user currently is.

Unrecoverable errors, eg system failure, authentication / authorisation errors etc should be redirected to an error page.

So a Struts app has to fork flow of control by distinguishing which error has occurred. One approach is to wrap all exceptions coming out of the business layer in either one or the other bespoke exception, and to let the Struts app switch flow based on the class of exception, e.g. MyAppRecoverableException and MyAppUnrecoverableException. The business delegate pattern provides layer which is a good place to do this.

There are further strategies for establishing what the messages to be displayed and logged should be.

Hope that helps.

Adam

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

Reply via email to