Announcement Announcement Module
Collapse
No announcement yet.
Controller not forwarding to different jsp controller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Controller not forwarding to different jsp controller

    Hi,
    I am a newbie at spring and would appreciate some help on this problem.

    I have these controllers and jsps defined in empapp-servlet.xml

    <bean id="empincontroller" class="EmpInController">
    <property name="sessionForm">
    <value>
    true
    </value>
    </property>
    <property name="commandName">
    <value>empObj</value>
    </property>
    <property name="commandClass">
    <value>Employee</value>
    </property>
    <property name="validator">
    <ref bean="empinValidator"/>
    </property>
    <property name="formView">
    <value>EmpView</value>
    </property>
    <property name="successView">
    <value>SuccessDisplay.htm
    </value>
    </property>
    <property name="EmployeeManager">
    <ref bean="empMgr"/>
    </property>
    </bean>


    <bean id="empoutcontroller" class="EmpOutController">
    <property name="sessionForm">
    <value>
    true
    </value>
    </property>
    <property name="commandName">
    <value>empListObj</value>
    </property>
    <property name="commandClass">
    <value>EmployeeList</value>
    </property>
    <property name="validator">
    <ref bean="emplistValidator"/>
    </property>
    <property name="formView">
    <value>SuccessDisplay</value>
    </property>
    <property name="successView">
    <value>SuccessDisplay.htm
    </value>
    </property>
    <property name="EmployeeManager">
    <ref bean="empMgr"/>
    </property>
    </bean>


    <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="/Employee.htm">empincontroller</prop>
    <prop key="/SuccessDisplay.htm">empoutcontroller</prop>
    </props>
    </property>
    </bean>

    I have defined the EmpInController and EmpOutController as of type SimpleFormController.

    What I intend is that on calling the first EmpView.jsp, I can enter employee details.
    On save, the flow should go to SuccessDisplay.jsp where all employees are listed.

    From SuccessDisplay.jsp I can select an employee and click on edit.


    Initially the call goes to formBackingObject method of empincontroller, validates, renders the
    view. On submit, the onSubmit method is called on controller after validation. Then I
    forward to the new jsp using
    return new ModelAndView("SuccessDisplay","list",allemplist);

    Now the problem starts. The SuccessDisplay.jsp is rendered, but the formBackingObject of empoutcontroller
    is not called. The view is displayed with the URL ~Employee.htm.

    Now on click of submit on SuccessDisplay view, the onSubmit method is called on empincontroller.

    Can somebody please tell me what am I missing here?

  • #2
    If you need to forward to EmpOutController you could use RedirectView. Just redirecting to an JSP would not call EmpOutController.

    return new ModelAndView(new RedirectView("SuccessDisplay.htm")); Would call EmpOutController and thus its formBackingObject

    Comment


    • #3
      Thanks,
      that seems to do the calling fine.

      However I need to return the list to the new view.
      I have declared the view resolver as follows :

      <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
      <property name="viewClass">
      <value>org.springframework.web.servlet.view.JstlVi ew</value>
      </property>
      <property name="prefix"><value>/WEB-INF/jsp/</value></property>
      <property name="suffix"><value>.jsp</value></property>
      </bean>

      Which is the best approach to do this?
      TIA

      Comment


      • #4
        Is there no solution to this then ?

        Comment


        • #5
          If you want to return some data to the new view you simply pass it along like this
          return new ModelAndView(new RedirectView("SuccessDisplay.htm"), "list", list);

          Comment


          • #6
            Originally posted by seeker View Post
            Hi,
            I am a newbie at spring and would appreciate some help on this problem.

            I have these controllers and jsps defined in empapp-servlet.xml

            <bean id="empincontroller" class="EmpInController">
            <property name="sessionForm">
            <value>
            true
            </value>
            </property>
            <property name="commandName">
            <value>empObj</value>
            </property>
            <property name="commandClass">
            <value>Employee</value>
            </property>
            <property name="validator">
            <ref bean="empinValidator"/>
            </property>
            <property name="formView">
            <value>EmpView</value>
            </property>
            <property name="successView">
            <value>SuccessDisplay.htm
            </value>
            </property>
            <property name="EmployeeManager">
            <ref bean="empMgr"/>
            </property>
            </bean>


            <bean id="empoutcontroller" class="EmpOutController">
            <property name="sessionForm">
            <value>
            true
            </value>
            </property>
            <property name="commandName">
            <value>empListObj</value>
            </property>
            <property name="commandClass">
            <value>EmployeeList</value>
            </property>
            <property name="validator">
            <ref bean="emplistValidator"/>
            </property>
            <property name="formView">
            <value>SuccessDisplay</value>
            </property>
            <property name="successView">
            <value>SuccessDisplay.htm
            </value>
            </property>
            <property name="EmployeeManager">
            <ref bean="empMgr"/>
            </property>
            </bean>


            <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
            <property name="mappings">
            <props>
            <prop key="/Employee.htm">empincontroller</prop>
            <prop key="/SuccessDisplay.htm">empoutcontroller</prop>
            </props>
            </property>
            </bean>

            I have defined the EmpInController and EmpOutController as of type SimpleFormController.

            What I intend is that on calling the first EmpView.jsp, I can enter employee details.
            On save, the flow should go to SuccessDisplay.jsp where all employees are listed.

            From SuccessDisplay.jsp I can select an employee and click on edit.


            Initially the call goes to formBackingObject method of empincontroller, validates, renders the
            view. On submit, the onSubmit method is called on controller after validation. Then I
            forward to the new jsp using
            return new ModelAndView("SuccessDisplay","list",allemplist);

            Now the problem starts. The SuccessDisplay.jsp is rendered, but the formBackingObject of empoutcontroller
            is not called. The view is displayed with the URL ~Employee.htm.

            Now on click of submit on SuccessDisplay view, the onSubmit method is called on empincontroller.

            Can somebody please tell me what am I missing here?

            It looks like you are forwarding to your SuccessView.jsp page, not the SuccessView.htm => empoutcontroller (mapped via the SimpleUrlHandlerMapping).

            Code:
             
            <property name="successView">
            <value>forward:/SuccessDisplay.htm</value>
            also, replace the following

            Code:
            return new ModelAndView(super.getSuccessView(),"list",allemplist);
            Last edited by TrevorIngs; Sep 3rd, 2007, 08:17 AM. Reason: Fix code post error

            Comment

            Working...
            X