Reputation: 969
I am having serious problems with code I have written with Spring so I have decided to start from scratch and ask for advice. Here are my requirements:
I have been using SimpleFormController and the referenceData() and onSubmitAction() methods but I'm not sure if this is the best solution. I think my problem is that after onSubmitAction is finished the list of objects is not available in the JSP as referenceData() is not called after onSubmitAction() finishes.
Apologies if this is a silly request. I have been googling and looking for tutorials for 2 days and I cannot find an example that does what I need it to do.
So my question is which methods should I be implementing to meet these requirements?
Upvotes: 0
Views: 1717
Reputation: 1251
This can be solved in a few different ways:
successView
to something that will forward to the form command as if it were an initial request (e.g. set a parameter or something that indicates the form shouldn't be resubmitted)successView
to a redirect back to the original form. (e.g. redirect:/some/url
)referenceData
method to populate the request attributes you need.1 and 2 have the advantage of reusing your existing form display logic. In addition, 2 has the advantage of avoiding a submit if the user reloads the page after submitting the form once.
Upvotes: 0
Reputation: 14265
The confusing thing to me about your question is the onSubmitAction() call -- are you using the Spring portlet code or the servlet code?
If you're using the portlet code, then you should be OK also overriding onSubmitRender() to return a RedirectView redirecting the user back to the same page. As you say, if you use the same page as your default success view, you don't go back through the referenceData() call; if you instead redirect your user to the page, the user is taken through the entire page-load process which includes the referenceData() call. So you just have to include an overridden onSubmitRender() which returns something like this:
return new ModelAndView(new RedirectView(url, true));
If you're using the servlet code, there's no onSubmitAction(), only onSubmit() -- and at the end of your overridden onSubmit(), you'd do the same as above, returning a new RedirectView() to your same page.
Upvotes: 0
Reputation: 5491
The old Spring way of using the Controller class hierarchy has lots of drawbacks compared to the newer, more flexible way of using annotation based controllers.
That said, have you tried to send a redirect after processing the form submission? This both solves the problem of the user being prompted if it's ok to resubmit the form if he reloads the page.
Upvotes: 1