PDA

View Full Version : HELP! Can the "view" from one form be another form?



DaveM
Feb 28th, 2006, 08:48 PM
Good afternoon. Please forgive the newbie question, but I can't seem to work this out or find it in the documentation.

I have a very simple form (it only consists of one submit button) which has a controller of type SimpleFormController. The onSubmit method then returns a MAV that directs to another page.

When that page is a plain JSP (html) page, everything works without a problem.

However when I set the MAV to direct the result to another JSP page containing a form (that also uses a different SimpleFormController) I get the following exception generated when I attempt to access the servlet via it's web interface:

'org.apache.jasper.JasperException: Neither Errors instance nor plain target object for bean name 'stringStore' available as request attribute'

Both pages and controllers work fine on their own, but for some reason not together - which would lead me to believe that one form cannot direct to another, but that would seem to me to be an unlikely limitation.

I'll include all the code here so that maybe someone may be able to tell me what on earth I am doing wrong!

--------------------------------------------------------------------------
Controller number 1 (to handle just a simple "Start" button on a form):
--------------------------------------------------------------------------
public class startTestFormController extends SimpleFormController {

public ModelAndView onSubmit(Object command) throws ServletException, IOException
{
return new ModelAndView("main");
}

protected Object formBackingObject(HttpServletRequest request) throws ServletException
{
return new Object();
}
}

--------------------------------------------------------------------------
Controller number 2 (to handle a barely more complex input):
--------------------------------------------------------------------------

public class testFormController extends SimpleFormController {

public ModelAndView onSubmit(Object command) throws ServletException, IOException
{
Map myModel = new HashMap();
Stringstore theString = (Stringstore)command;
myModel.put("myString", theString.getWord());
return new ModelAndView("success","model",myModel);
}

protected Object formBackingObject(HttpServletRequest request) throws ServletException
{
return new Stringstore();
}
}

--------------------------------------------------------------------------
The slice of XML where the two controllers are set up and invoked:
--------------------------------------------------------------------------
<beans>
<bean id="mastercontroller" class="testFormController">
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>stringStore</value></property>
<property name="commandClass"><value>Stringstore</value></property>
<property name="formView"><value>main</value></property>
<property name="successView"><value>main</value></property>
</bean>

<bean id="startcontroller" class="startTestFormController">
<property name="sessionForm"><value>true</value></property>
<property name="formView"><value>start</value></property>
<property name="successView"><value>start</value></property>
</bean>

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="mappings">
<props>
<prop key="/start.htm">startcontroller</prop>
<prop key="/main.htm">mastercontroller</prop>
</props>
</property>
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResou rceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="prefix"><value>/WEB-INF/jsp/</value></property>
<property name="suffix"><value>.jsp</value></property>
</bean>
</beans>

--------------------------------------------------------------------------
Here is main.jsp which is invoked as a success from the "success" of the first controller:
--------------------------------------------------------------------------
<%@ include file="/WEB-INF/jsp/include.jsp" %>
<%@ taglib prefix="spring" uri="/spring" %>
<html>

<head><title>My Title</title></head>

<body>

<h1>My Heading</h1>
<br/>
<form method="post">
<spring:bind path="stringStore.word">
<input type="text" name="word">
</spring:bind>
<input type="submit" alignment="center" value="My Button">
</form>
</body>

</html>

--------------------------------------------------------------------------

Is anyone able to tell me what it is that I am not understanding?
Would be muchly appreciated.

DaveM
Feb 28th, 2006, 09:45 PM
Disregard, I think I've got it figured....

I had to use a return new ModelAndView(new RedirectView(getSuccessView())) at the end of my onSubmit method to force it to do a complete GET for my second form.

If someone has a good way of explaining what is happening in both scenarios I'd be happy to learn. Thanks.