Announcement Announcement Module
No announcement yet.
Problem with multiple SimpleFormControllers and bean not being initialized Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with multiple SimpleFormControllers and bean not being initialized

    My project
    Basically I have two jsp files with forms.

    second.jsp ; controller is SecondController ; form view = second ; success view = third ; form method='post' action='second.html'
    third.jsp ; controller is ThirdController ; form view = third ; third view = fourth ; form method='post' action='third.html'

    third.jsp correctly displays the data submitted in second.jsp. But if I try to add another form into third.jsp, I get errors saying the bean doesn't exist.

    The Error
    If on "second.html" page, I submit a form, I get this error :
    "Neither BindingResult nor plain target object for bean name 'thirdBean' available as request"

    Why is the "thirdBean" not being created?

    What works
    If I go directly to URL "localhost:8080/third.html", then I don't get any errors. The "thirdBean" is created and binding occurs correctly.

    What could be wrong?
    When I go to "third.html" directly, the thirdBean object is created correctly. But when I go through "onSubmit" of SecondController, then the thirdBean object is not created.
    So I suspect that I need to change something in onSubmit

    Code samples
    protected ModelAndView onSubmit() {
    SecondGreeting cmd =(SecondGreeting)command;
    return new ModelAndView("third", "command", cmd);


    <spring:bind path="thirdBean.maindish">
    Maindish: <input type="text" name="maindish" value="<c:out value="${status.value}"/>">
    <font color="red"><c:out value="${status.errorMessage}"/></font>
    </spring:bind> <br>



    <bean id="secondForm" class="greeting.SecondGreeting"/>
    <bean id="thirdBean" class="greeting.ThirdOrder"/>

    <bean id="thirdController" class="greeting.ThirdController">
    <property name="sessionForm"><value>true</value></property>
    <property name="commandName"><value>thirdBean</value></property>
    <property name="commandClass"><value>greeting.ThirdOrder</value></property>
    <property name="formView"><value>third</value></property>

    <bean id="secondController" class="greeting.SecondController">
    <property name="sessionForm"><value>true</value></property>
    <property name="validator">
    <bean class="greeting.MySecondValidator" />
    <property name="commandName"><value>secondForm</value></property>
    <property name="commandClass"><value>greeting.SecondGreeting </value></property>
    <property name="formView"><value>second</value></property>
    <property name="successView"><value>third</value></property>

    <bean id="urlMapping"
    class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <prop key="/second.html">secondController</prop>
    <prop key="/third.html">thirdController</prop>

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



  • #2
    I am really new to Web development, Spring and MVC. So, I'll really appreciate any help/suggestions.