views:

45

answers:

2

My starting problem is this error message:

Problem accessing /segment.htm. Reason:

Neither BindingResult nor plain target object for bean name

'acceptCorrected' available as request attribute

The top-level description of what I'm working on is this:

Form1 solicits some input from the user. When form1 submits, I need to push that data through some processing, and then present form2, containing the results of the processing. I am trying to communicate the results of form1 to form2 via the model returned by form1's controller's onSubmit.

There's reason to believe that this is verboten.

But, if it is, how do I get the data from1 to be available when rendering the JSP page for form2?

<bean name="/segment.htm" class="com.basistech.rseharvest.SegmentFormController">
  <property name="sessionForm" value="true"/>
  <property name="commandName" value="segment"/>
  <property name="commandClass" value="com.basistech.rseharvest.Segment"/>
  <property name="validator">
   <bean class="com.basistech.rseharvest.SegmentValidator"/>
  </property>
  <property name="formView" value="segment"/>
  <property name="successView" value="showSegmented"/>
  <property name="segmenter" ref="segmenter"/>
 </bean>

 <!--  the page to enter text -->
 <bean name="/showSegmented.htm" class="com.basistech.rseharvest.AcceptCorrectedFormController">
  <property name="sessionForm" value="true"/>
  <property name="commandName" value="acceptCorrected"/>
  <property name="commandClass" value="com.basistech.rseharvest.AcceptCorrected"/>
  <property name="validator">
   <bean class="com.basistech.rseharvest.CorrectionsValidator"/>
  </property>
  <property name="formView" value="showSegmented"/>
  <property name="successView" value="segment"/>
  <property name="data" ref="data"/>
 </bean>
+1  A: 

The onSubmit of the first form returns a ModelAndView pointing to the second form, by naming the same view as you see as the formView of the second form.

Can you explain a little further what this means? Is the "segment" view rendering HTML that contains a <form> that POSTs to /showSegmented.htm?

formBackingObject() is only called on the initial GET request to the page.

Do you want /segmented.htm to display the form and /showSegmented.htm to handle the processing of the input values?

If so, this isn't really the intended usage of AbstractFormController. This class is intended to be used in situations where you want the same controller to handle 1) the presentation of the form and 2) the processing of it's submission.

matt b
bmargulies
I'm confused though, because you seem to have two form controllers posted in your code sample above. When using AbstractFormController (and it's subclasses), I believe the intended usage is that the same controller instance (and URL mapping) is used for both the form presentation (the GET) and handling submission (the POST). In other words, you should need only one <bean> controller mapped and one URL.
matt b
Have you seen the "Developing a Spring Framework MVC application step-by-step" tutorial? Doesn't look like it's been updated for 3.0 but it's a good starting resource http://static.springsource.org/docs/Spring-MVC-step-by-step/ The section on form controllers might be helpful http://static.springsource.org/docs/Spring-MVC-step-by-step/part4.html#step4.6
matt b
Yes, that tutorial is what got me into this mess in the first place.
bmargulies
@matt I do have one controller handling GET and POST of *each of two forms*. Thus, two forms, two controllers.
bmargulies
A: 

Hours of messing around seem to have left me with an answer. I'm not sure it's perfect, but it might help other people. There are tons of people frustrated out there with the error message at the top of this question.

In Spring 2.5.6, there is either a bug or a strange limitation, as follows. If a SimpleFormController specifies, as its successView, another page with a SimpleFormController, the second one will fail as in the question. The post data from the first form seems to interfere with what happens on the second form. There seems to be an assumption that the next view after a form is submitted is always a non-form.

If the first page uses a RedirectView to hand off to the second page, all is well.

There are many conflicting pieces of advice, in some cases coming from conflicting heavy-hitters at on the Spring forums, about this. All I know is I made the error posted in the question go away by switching to a redirect. Now the browser does a plain GET of the page for the successView, and the model sets up correctly, and all is well.

Note in passing that the argument to RedirectView is the 'outside' URL (in the tutorial, something like blah.htm) and not the simple token that the mapper maps to JSP pages.

bmargulies