Different views with Spring SimpleFormController

I am using Spring SimpleFormController to process the form. In my case, the editing view (JSP) may vary depending on what is being edited. SimpleFormController formView is a field (class variable), which means that it is shared by all threads using its instance. Thus, it is unsafe (and not necessary) to set formView (via setFormView ) to formBackingObject . My question is, is it possible to use SimpleFormController with various kinds of editing based on some context?

Follow up actions . showForm(HttpServletRequest req, HttpServletResponse resp, BindException errors) looking at the source, I can override showForm(HttpServletRequest req, HttpServletResponse resp, BindException errors) and call showForm(HttpServletRequest req, BindException errors, String viewName) with whatever view I want.

+1
java spring
source share
2 answers

I believe that SimpleFormController provides two protected showForm methods. They can be overridden and a BindException is used to retrieve the "target" that is your form object, then you can return a ModelAndView based on any property of the associated form object. You should also take a look at processFormSubmission, it dictates which methods are actually called. Another method is "isFormChangeRequest", which determines whether your form should change - you can use this to set this to true, and then call showForm with the request, response, etc., And you can re-examine the request.

The only way to learn how to use this hierarchy is to study it. This is not very good - it provides a lot of things, but not very good. Spring MVC usually needs to be expanded to be very useful.

+3
source share

I do not think this is possible with SimpleFormController.

You can try to stop using controller hierarchy classes that will still become obsolete, and take a look at annotation-based controllers introduced with Spring 2.5. They provide more flexible form processing. Do not procrastinate if you do not like automatic injection. Although none of the examples makes this obvious, you can use annotation-controlled controllers and define all beans in the XML content.

0
source share

All Articles