PDA

View Full Version : FormBackingObject not saved in session



bknights
Aug 19th, 2004, 01:58 PM
Hi,

I am wanting to have a form that has two submit buttons. One of them does the actual submit and one of them retrieves some data and populates a select object on the form. When I populate the select ojbject I want to preserve any entries already made on the form.

I'd have thought that the sessionForm parameter would be the way to do this.
e.g.
the servlet configuration:
<bean id="searchItemsController" class="web.SearchItemsFormController">
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>searcher</value></property>
<property name="commandClass"><value>com.ledgerdemain.matrixeditor.MatrixItemSearcher</value></property>
<property name="formView"><value>searchTargetsForm</value></property>
<property name="successView"><value>searchTargetsForm</value></property>
</bean>


<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="mappings">
<props>
<prop key="*">searchItemsController</prop>
</props>
</property>
</bean>

the controller class:

public class SearchItemsFormController extends SimpleFormController {

/** Logger for this class and subclasses */
protected final Logger logger = Logger.getLogger(this.getClass().getName());

private MatrixItemSearcher searcher;

public ModelAndView onSubmit(Object command)
throws ServletException {

MatrixItemSearcher searcher = ((MatrixItemSearcher) command);

return new ModelAndView(new RedirectView(getSuccessView()));
}

protected Object formBackingObject(HttpServletRequest request) throws ServletException {

MatrixItemSearcher searcher = new MatrixItemSearcher();
searcher.setSearchManagedItems(false);
searcher.setSearchLDMarkedItems(true);
searcher.setItemName("Fred");

return searcher;

}

Its success view just currently redirects back to itself.

In searching the Spring code I can't find anyplace where session.setAttribute is called on the object returned by the initial getFormBackingObject call.

arsenjew
Aug 20th, 2004, 04:35 AM
The <sessionForm> property does not indicate that the command object is stored in the session permanently; instead, it only toggles whether the formBackingObject is stored in the session scope while the form workflow is in progress (e.g. to preserve the same formBackingObject over various attempts to submit the form that result in validation errors); once the workflow is completed successfully, the formBackingObject is removed from the session scope. So I'd guess what happens in your case is this: When the user clicks on the submit button that's supposed to fill the select value lists, the form is submitted, the workflow is completed and an entirely new form workflow starts.
Maybe you should try using the AbstractWizardFormController instead.

lemiorhan
Aug 20th, 2004, 06:02 AM
Hi,

You may add the command object (that is, formBackingObject) in onSubmit method in your controller to the session by session.addAttribute(obj) and access wherever you want.

Here, in your code, FormBackingObject is being lost because after you redirect to the successview, a new fbo is generated.

--
Lemi Orhan Ergin

YSutarko
Aug 25th, 2004, 08:40 AM
hi.. i dont know if im right .. but i think you should do it like this:




import org.springframework.validation.BindException;

...

public ModelAndView onSubmit&#40;Object command&#41;
throws ServletException &#123;

MatrixItemSearcher searcher = &#40;&#40;MatrixItemSearcher&#41; command&#41;;

BindException errors = new BindException&#40;searcher, "searcher"&#41;;

return new ModelAndView&#40;errors.getModel&#40;&#41;&#41;;
&#125;

bknights
Aug 25th, 2004, 12:36 PM
Thanks for everyone's help on this.
It turns out I didn't want the command saved in the session anyway.

sam.java
Oct 15th, 2007, 02:26 AM
I am using a spring based framework.I am using a controller that extends from BaseFormController.I have one jsp form that should be validated before clicking on the next button to a secong form.If validation is sucessfull then a second form is filled, validated and on clicking on the submit button the data on both forms enter the database.how can i do this?how is the formBackingObject() used?