• Post Reply Bookmark Topic Watch Topic
  • New Topic

Questions about passing model tier exceptions to Struts  RSS feed

 
Ranch Hand
Posts: 96
Scala Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am working solo on a 2 year old Struts project. 100% of the validation is currently being done with the validate method in my extensions of the ActionForm class.

My understanding is that the presentation tier should be doing things such as:

if (inputString.length > 3) return error;

Whereas, the model should throw exceptions back to the presentation tier such as:

if (location1.getNumCars() > location2.getNumCar()) throw new BusinessException("Num Cars at loc 1 cannot be greater than num cars at loc 2);

Is this a reasonable line of thought? If so, my idea is to place many of my complicated business logic rules revolving around valid creation of a model object inside the various model object constructors. Then when I'm constructing my model object, I'll throw a BusinessException back to the presentation tier if something inappropriate took place. Again, would this be a normal way to do this?

If I'm still ok, I'm assuming that I can package a collection of messages inside one BusinessException since I'd want to let the presentation tier know of all problems given a call to a model object constructor.

Any thoughts or links on this topic is greatly appreciated.
[ February 15, 2006: Message edited by: Samuel Cox ]
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you are describing sounds close to what my project is doing. The presentation layer handles basic validation through a combination of the validator framework and validate methods. Complex validation is handled in the business layer. My project just throws a validation exception on the first error, but I could see where it would be fairly easy to have a custom exception that could hold a list of error messages.

One thing that I don't like about our implementation is that the messages that get stuck on the exception, and that get displayed to the user, are baked into the code. Not ideal, but it works.

In my base action class I have code that traps all exceptions (actually Throwable). He is the code (slightly modified). You can see where it checks for a ValidationFailedException and treats it like a validation error.


- Brent
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!