Results 1 to 6 of 6

Thread: Another newbiew question re form control

  1. #1

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    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
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3

    Default

    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

  4. #4
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    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

  5. #5
    Join Date
    Oct 2004
    Location
    London, UK
    Posts
    71

    Default

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

  6. #6

    Default

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

Similar Threads

  1. Replies: 3
    Last Post: Jun 8th, 2010, 03:27 AM
  2. Replies: 3
    Last Post: Apr 29th, 2005, 06:09 AM
  3. Replies: 0
    Last Post: Feb 22nd, 2005, 11:26 PM
  4. Updating Form control
    By afida in forum Swing
    Replies: 10
    Last Post: Dec 5th, 2004, 07:37 PM
  5. Question regarding the Form Model
    By Catalin Sanda in forum Swing
    Replies: 2
    Last Post: Sep 21st, 2004, 12:44 AM

Posting Permissions

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