Results 1 to 4 of 4

Thread: forwarding data to a form

  1. #1
    Join Date
    Apr 2005
    Posts
    14

    Default forwarding data to a form

    I have some questions concerning forwarding data to a form. I have a situation where a form on my site is submit and upon sucess another form is displayed and initialized.

    I have overridden onSubmit() in my first form and am creating the command class that the second form expects such as:

    return new ModelAndView(getSuccessView(), "myModelObject", myModelObject);

    I am ok up to this point. However, I'm confused about two things. First, when my subsequent form is invoked, my formBackingObject() method is not being called. However, the jsp for my form IS being rendered. I have setup the successView property of my initial form to the logic view name of the second form? Isn't this correct? My controller isn't being invoked on the second form but the jsp is being rendered. Why is this?

    Second question is how do I access the data that was passed along to the second controller inside of its formBackingObject() method? Will the object just be an attribute in the request?

  2. #2
    Join Date
    Aug 2004
    Location
    Hawaii, US
    Posts
    225

    Default

    Quote Originally Posted by aharvey
    My controller isn't being invoked on the second form but the jsp is being rendered. Why is this?
    What is the value of successView? It sounds like it is the JSP. Instead, change it to the Controller. You can do this just like any other InternalResourceView, because from the Servlet API's perspective, a JSP and a Servlet (controller) are the same thing. It will just use the RequestDispatcher to forward along the request.

    Second question is how do I access the data that was passed along to the second controller inside of its formBackingObject() method? Will the object just be an attribute in the request?
    Putting the object into the request is the way to do it. In fact, this is essentially what happens to the objects inside the ModelAndView.

  3. #3
    Join Date
    Apr 2005
    Posts
    14

    Default

    unless i'm mistaken, setting the successView to a controller seems to just render the associated jsp. I set the successView to redirect:myController and this causes the normal formBackingObject() method to be called.

    thanks for the tip of grabbing the object from request. i'll try that within my formBackingObject() method.

  4. #4
    Join Date
    Aug 2004
    Location
    Hawaii, US
    Posts
    225

    Default

    Just a word of caution... if you are redirecting with redirect:, it will issue a HTTP redirect. This method will create a new request, and anything you place into it will be lost. If you want to redirect, you will need to store things inside the session.

Posting Permissions

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