struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Nenning <Christoph.Nenn...@lex-com.net>
Subject Antwort: Showing Action Exception as Ajax Errors
Date Fri, 15 Nov 2013 09:39:36 GMT
> Hi,
> 
> We are using struts2 JSONValidationWithInterceptor. This interceptor
> grabs the errors from validation and convert them to json message
> How can we have same feature! An interceptor which grabs the action 
> exceptions and serialize them as json errors.
> 
> I try below interceptor. When an exception happens it works, when 
> there are no errors and I should pass {} to response it is not working!
> _______________________________________________
> 
> String target=Action.NONE;
>         try {
>              target=invocation.invoke();
>              response.getWriter().print("{}");                
>             response.setContentType("application/json");
>              return target;
>         }
> 

invocation.invoke() does these things:
- execute remaining interceptors
- execute action
- execute result (e.g. rendering a JSP)
- execute remaining interceptors again (what they do after 
invocation.invoke())


So, when no exception is thrown the response has already been created and 
the lines
  response.getWriter().print("{}");
  response.setContentType("application/json");
have no effect.


You can try to change the action to return Action.NONE

This Email was scanned by Sophos Anti Virus

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message