-
Nov 9th, 2012, 08:13 AM
#1
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
SecondController
protected ModelAndView onSubmit(…) {
SecondGreeting cmd =(SecondGreeting)command;
return new ModelAndView("third", "command", cmd);
}
Third.jsp
<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>
app-config.xml
<beans>
<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>
<bean id="secondController" class="greeting.SecondController">
<property name="sessionForm"><value>true</value></property>
<property name="validator">
<bean class="greeting.MySecondValidator" />
</property>
<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>
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/second.html">secondController</prop>
<prop key="/third.html">thirdController</prop>
</props>
</property>
</bean>
<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/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules