PDA

View Full Version : doSubmitAction() ignores referenceData()


ojs
Oct 5th, 2005, 12:31 PM
Hallo,

I'd like to use doSubmitAction() instead of onSubmit() in a simple controller, but obviously my referenceData() is called but the returned Map isn't merged with the ModelAndView.

Code that work:


@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
throws Exception
{
// ... my save methods ...

return showForm(request, response, errors);
}



Code that doesnt' work:


@Override
protected void doSubmitAction(Object command)
throws Exception
{
// ... my save methods ...
}



In the latter case the form is correctly redisplayed, but all data set by referenceData() is missing.


Any hints?



Best
Oliver

macob
Oct 8th, 2005, 10:40 PM
The doSubmitAction does not call referenceData because it is expected that after a succesful form submission, you would forward to a "success" page and not back to the form.

The Form controller is handles 2 types of requests:

The Request to get the form page for the user to enter data.
(This needs to be an HTTP "GET" request). The Form Controller will internally use the "showForm", which will call "referenceData", the idea being that a Form probably has drop down lists, radio buttons, etc. and referenceData can be used to supply values for these things.


The use fills out the form and submits back to the form controller (This needs to be an HTTP "POST" request). The "doSubmitAction" will handle the form submit, update a database or do whatever with the data the user entered. It is then expected that the user will be forwarded to some kind of "success" page, where there would be no need for the form reference data, hence "referenceData" is not called.

If you really need to send the user back to the form after a successful form submission, then I think calling "showForm" yourself is a good idea (like your first code snippet does).

Colin Yates
Oct 10th, 2005, 05:02 AM
you might also find it useful to know that SFC will call isFormSubmission to determine whether it is a "get" or a "post".