Announcement Announcement Module
Collapse
No announcement yet.
Global errors Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Global errors

    Hello fellows!
    Is there a simple way to add global errors from a controller class implementing Controller interface?

    Code:
    public class MyController implements Controller {
        
        public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) {
            
            // som logic..
    
            // want to add global error here!!
    
            ...
    
            return new ModelAndView(...);
        }
    }
    /Tony

  • #2
    Hi,

    what do you mean with "global error"? You can put an error message into your model, if this is what you want.

    Regards,
    Simon

    Comment


    • #3
      Well I'm kind of new to this mvc framework so I'm not sure how the error handling works.

      Do I have to create a BindException object or is there another approach to add a simple error message?

      /T

      Comment


      • #4
        I believe you can just do one of these:

        Code:
        public class MyController implements Controller {
            
            public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) {
                
                // some logic..
                Command command = new Command();
                command.setThingie("thing");
                ServletRequestDataBinder binder = new ServletRequestDataBinder(command, "command");
                binder.bind(request);
        
                // want to add global error here!!
                binder.getErrors().reject("global1", "global error #1");
                ...
        
                // Add some field specific errors....
                ValidationUtils.rejectIfEmpty(binder.getErrors(), "thingie", "empty", "error on thingie field");
        
                return new ModelAndView("thing", binder.getErrors().getModel());
            }
        }

        Comment


        • #5
          You might want to look at the code for the AbstractViewController in my Spring MVC extension modules:-

          http://cvs.sourceforge.net/viewcvs.p...va?view=markup

          If you look at the handleRequest method you'll see the BindException object being created and then passed through into the abstract process method which means that all sub-classes get the Errors object in the same way as form controllers.

          Comment

          Working...
          X