Maybe there weren't a lot of comments because people agreed with Robert.  :)

For your followup, the reason you get one of (a) and (b) is because
you're thinking that the error message should come from the business
tier.  I like to think that it shouldn't.  Error messages are a
presentation tier responsibility.  In the business tier, the exception
should be able to communicate with other objects what the error was. 
The way I do this is with specific exception types or with error
codes.  If the exception is caught by another business tier object, it
can check the error code to see what exactly happened.  If it bubbles
up all the way to the presentation tier, it can do the same, and then
select an i18n error message to show, or other take other action as
needed.

hth,
Hubert


On Wed, 08 Sep 2004 10:49:25 +0000, Janne Mattila
<[EMAIL PROTECTED]> wrote:
> Hmm, not a lot of comments on this. I guess there is a consensus on the
> matter (that, or no-one really gives a damn).
> 
> A quick followup on this; how could I achieve both
> 
> a) decoupling of my business classes from Struts
> b) internationalization
> 
> if I validate in my business class?
> 
> 1)
> if (alreadyExists(email)) {
>   throw new MyAppException("E-mail address already exists");
> 
> achieves a) but not b), and
> 
> 2)
> if (alreadyExists(email)) {
>   throw new MyAppException("errors.email.duplicate");
> 
> achieves b) but not a)
> 
> >From: "Robert Taylor" <[EMAIL PROTECTED]>
> >Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> >To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> >Subject: RE: Proper place for validation
> >Date: Tue, 7 Sep 2004 08:21:09 -0400
> 
> >From: "Robert Taylor" <[EMAIL PROTECTED]>
> >Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> >To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> >Subject: RE: Proper place for validation
> >Date: Tue, 7 Sep 2004 08:21:09 -0400
> 
> 
> >
> >I would avoid putting any business logic in the action
> >class. Place this type of logic in the business class as it
> >most likely is validation that is valid across all application
> >logic and not for just one use case.
> >
> >robert
> >
> > > -----Original Message-----
> > > From: Janne Mattila [mailto:[EMAIL PROTECTED]
> > > Sent: Tuesday, September 07, 2004 8:15 AM
> > > To: [EMAIL PROTECTED]
> > > Subject: Proper place for validation
> > >
> > >
> > > I am wondering what would be the propert place for some validation code.
> > > Let's say I have a registration page where user inputs his/her
> >information
> > > for a new user account. There's a field for e-mail address. On one level
> > > that information is validated on the ActionForm, for things such as
> > >
> > > - field is not left empty, if it is required
> > > - field is a valid e-mail address
> > >
> > > That much seems quite clear. But where should I put a check that ensures
> > > that same e-mail address is not already used by an existing account?
> > >
> > > On the other hand, I could put it in the registration action, because
> > > checking that is (kind of) user-input validation, and action is a
> >natural
> > > place to do this.
> > >
> > > On the other hand, I could put it in my business class. The pros for
> >this
> > > would be smaller and simpler action code, and reuse if same check is
> >needed
> > > with different actions.
> > >
> > > Any suggestions? Intuitively, I think I would put that check in the
> >Action,
> > > but I am happy to hear any arguments in favor or opposing that.
> > >
> > >

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

Reply via email to