struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alireza Fattahi <afatt...@yahoo.com>
Subject Showing Action Exception as Ajax Errors
Date Fri, 15 Nov 2013 09:03:02 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;
        }

        catch (BussinessException ex) {
            StringBuilder sb = new StringBuilder();
            sb.append("{ ");
            sb.append("\"errors\": [\"");
            sb.append("Bussiness Exception Happend");
            sb.append("\"]}");
            response.setContentType("application/json");
            response.getWriter().print(sb.toString());    
            return Action.NONE;
         
        }


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