[ 
https://issues.apache.org/jira/browse/WW-4234?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13806374#comment-13806374
 ] 

Lukasz Lenart commented on WW-4234:
-----------------------------------

But you must return some result from your interceptor - right now you return 
null, which means "stop processing". And how you want to get result as before 
you return it ({{return SUCCESS}}) you have thrown exception?

And what you mean by "return to the same page"? What page?

And please ask such questions on Struts Users Mailing List 
<[email protected]> - JIRA isn't the place to discuss your architectural 
problems ;-)

> Ability to catch service layer exceptions at one place and allow adding 
> action messages/errors before results are rendered
> --------------------------------------------------------------------------------------------------------------------------
>
>                 Key: WW-4234
>                 URL: https://issues.apache.org/jira/browse/WW-4234
>             Project: Struts 2
>          Issue Type: Improvement
>    Affects Versions: 2.3.15.3
>            Reporter: Shailesh Arvind Vaishampayan
>            Priority: Minor
>             Fix For: 2.3.x
>
>
> I am working with an application involoving Struts2 in web layer and Spring 
> in business layer. I also have BusinessException class which will be used by 
> all business services to create business related validation failures which 
> must go up to web layer and should be show to users as validation message. I 
> can easily do this by writing in my Action class:
> {code:java}
>       ClientAction extends ActionSupport throws Exception{
>          ....
>         try{
>             clientService.searchClient();
>         }catch(InvalidClientSearchCriteriaException e){
>               addActionMessage("Invlid Search Criteria");
>         }
>         ...
> {code}
> And similar code in every action class. However i dont want to pollute my 
> action classes with try catch blocks. Instead it would be much better if i 
> can write on try catch block at one place and catch all the exceptions there 
> as BusinessExceptions and create messages /errors from embedded 
> messages/errors in those exceptions. One approach i could think of was to use 
> interceptor or preResultListener. But I cannot use interceptor like below 
> which catches business exceptions thrown from action classes...
> {code:java}
>     ExceptionInterceptor extends AbstractInterceptor(ActionInvocation 
> ivocation,...){              
>           try{
>                     invocation.invoke();
>           }catch(Exception e){
>               if(e instanceof BusinessException){
>                    ActionSupport as = (ActionSupport)invocation.getAction();
>                    String message = extractMessagefromException()//--custom 
> method to extract message embedded in exception.  
>                as.addActionMessages(message);
>       //-- above will not work result has already been rendered right? and 
> hence it wouldn't matter if i add actoinmessages now.
>            }
>          }                                               
>    } 
> {code}
> Second approach of of preResultListener is to add action messages just like 
> above in preResultListener's method as result is yet to be rendered and i can 
> safely change that. However not sure if preResultListener will ever execute 
> if exception is thrown in action? and even if it does how i can get the 
> exception object thrown by the action.?
> There has to be something out of the box so that actions are not cluttered 
> with try-catch blocks



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to