Announcement Announcement Module
Collapse
No announcement yet.
Another newbiew question re form control Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Another newbiew question re form control

    <caveat> Usual please bear with me stuff </caveat>
    I have a form (lets call it FormA, in formA.jsp) with a SimpleFormController . namely FormAController.

    formA.jsp has a link to another form, formB. FormB (another SimpleFormController) allows me to select a parameter to pass back to formA. This works fine in as much that if I have in FormBController.onSubmit()
    {
    .......
    return new ModelAndView("formA", "myModel", model);
    }
    I am returned to formA with the correct value selected (ie the one I selected in formB) -but with formB.html in the browser url

    However , when I submit formA the form is submitted to the formB controller.
    How do I pass control back from FormBController to FormAController ? If I use a RedirectView I lose the the parameter and I get the class info displayed in the browser url

    My mappings are:-

    <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="/formA.html">formAController</prop>
    <prop key="/formB.html">formBController</prop>
    </props>
    </property>
    </bean>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="viewClass"><value>org.springframework.web.se rvlet.view.JstlView</value></property>
    <property name="prefix"><value>/jsp/</value></property>
    <property name="suffix"><value>.jsp</value></property>
    </bean>
    </beans>

  • #2
    If I use a RedirectView I lose the the parameter and I get the class info displayed in the browser url
    I find this quite strange!!!
    If you are using Spring Framework 1.1.2, try:
    Code:
      <bean id="formControllerB" class="...FormControllerB">
        <property name="successView"><value>redirect&#58;formA.html</value></property>
        ...
      </bean>
    HTH

    Comment


    • #3
      Thanks. What I was doing was :-
      formA ->formA
      in FormBController.onSubmit () I was creating a FormABean and setting the parameter chosen from formB. I was doing

      String name = formB.getName();
      FormABean formABean = new FormABean();
      formABean.setName(name);

      return new ModelAndView("formA", "formABean",formABean);

      This worked fine except, as I said when I submitted formA it went to FormBController. If I Redirected the view I lost the FormABean.


      However if I just returned the parameter chosen in formB to formA using a RedirectView I am able to pull the parameter from the request in FormAController.formBackingObject
      eg

      in FormB.onSubmit()

      return new ModelAndView(new RedirectView("formA.html"), "name",formB.getName());

      in FormAController..
      protected Object formBackingObject(HttpServletRequest request) throws ServletException {

      String name = request.getParameter("name");
      FormABean formABean= new FormABean();
      if(name != null){
      formABean.setName(name);
      }
      return formABean;

      }

      I

      Comment


      • #4
        If you have situations where more complex data (e.g. a Java object) needs to be exchanged between 2 controllers of your application, take a look at Spring Web Flows: http://www.ervacon.com/products/springwebflow/article.

        Erwin

        Comment


        • #5
          how about setting formA to use a session form? so the object is stored in the session and can be retrieved after form B.

          Comment


          • #6
            Thanks for the links and tips. Very useful, I'll off to inwardly digest

            Comment

            Working...
            X