Hello all,

I have a common problem that I'd like to be able to solve more cleanly
than I do.   I often have action beans that expose a piece of logic to
several different types of callers.  For example they may support the
same call via AJAX to which they return JSON, and as a regular web
request, to which they return HTML.  Typically I will set up a
different method on the action bean to handle each case and they will
both call some shared internal logic to do the operation but return
different resolutions with the results.

This is easily done except for two things:

 -  how to handle errors in validation of input parameters
 -  how to handle general errors in the execution of my action bean.

In both cases I want my JSON methods to return JSON formatted errors
and my HTML methods to return HTML pages displaying errors.  The
default behavior of Stripes is that my JSON methods all return HTML
errors which, of course, horribly breaks the parser at the other end.

For the validation case I tried implementing ValidationErrorHandler on
my action bean.  However this has to be done on a whole-bean basis - I
then have to put inside there some kind of switch logic that
differentiates the HTML cases from the JSON cases.  This feels very
unclean.   For the general error handler the only solution I've found
is to wrap every method call with an appropriate try / catch block
explicitly and return the appropriate content back from it.

None of this is very hard, but it has a real "square peg in round
hole" feel to it.   Does anybody know of cleaner solutions to handle
this kind of problem?    Will Stripes 1.5 offer anything new to help?

Thanks for any suggestions!

Simon.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to