Announcement Announcement Module
Collapse
No announcement yet.
forwarding data to a form Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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.

      Comment


      • #4
        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.

        Comment

        Working...
        X