Results 1 to 3 of 3

Thread: Confusion about controllers!

  1. #1
    Join Date
    Oct 2005
    Posts
    28

    Question Confusion about controllers!

    Hello everyone,

    I hope someone can help me out. I am little confused about Controllers.
    A controllers job is it to take the request, prepare the data, add it to the request (with spring add it to new ModelView for example). Is this right?

    For example if i have a page to choose different operations. The next view is an input form which differs depending on which operation was choosen.

    chooseoperation.jsp -> input.jsp

    with adding controllers it would look something like this

    chooseoperation.jsp -> Controller (prepare data) -> input.jsp

    but if input.jsp contains a form. i need a forward to the InputFormController not the input.jsp itself, right?

    must look something like this:

    chooseoperation.jsp -> Controller (preparing information for input dialog) -> InputFormController - uses view -> input.jsp

    right?
    can i forward from a class implementing Controller to a SimpleFormController?

    big thx in advance

  2. #2

    Default

    First of all, if you extend SimpleFormController this controller should prepare the data required to render the view with form. Have a look at the referenceData methods in SimpleFormController.

    Secondly, if your view can have multiple outcomes depending on which link or button you click on you can use MultiActionController. The methods on this controller can delegate to any controller you want, including a SimpleFormController.

    Code:
    public class ... extends MultiActionController {
        private Controller someFormController = null;
    
        public void setSomeFormController(Controller ctrl) {
            this.someFormController = ctrl;
        }
    
        public ModelAndView someAction(HttpServletRequest request, HttpServletResponse response) throws Exception {
            return this.someFormController.handleRequest(request, response);
        }
    }

  3. #3
    Join Date
    Oct 2005
    Posts
    28

    Default

    thx a lot! i think this is the anser to my question ;-)

    this also means a controller is not neccessarly processed only bevore or after an jsp is visited. right?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •