开发者

Spring MVC one form feeding data to another form

开发者 https://www.devze.com 2023-01-05 18:49 出处:网络
My starting problem is this error message: Problem accessing /segment.htm. Reason: Neither BindingResult nor plain target object for bean name

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.开发者_C百科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>


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消