Different views with Spring's SimpleFormController?

I believe SimpleFormController provides two "showForm" protected methods. These can be overridden and the BindException used to retrieve the "target" which is your form object, you can then return a ModelAndView based on any bound form object property. You should also take a look at processFormSubmission, it dictates which methods are called really.

Another method is "isFormChangeRequest" which determines whether or not your form should change - you can use this to set this to true and it will then call showForm with the request, response, etc. and you can then re-examine the request.

Up vote 0 down vote favorite share g+ share fb share tw.

I'm using Spring's SimpleFormController for form processing. In my case, the edit view (JSP) can vary depending on what's being edited. SimpleFormController's formView is a field (class variable) which means that it's shared by all threads that use the instance of it.

Thus it's not safe (nor appropriate) to set the formView (via setFormView) in formBackingObject. My question is, is it possible to use SimpleFormController with different edit views based on some context? Follow up: After looking at the source it appears that I can override showForm(HttpServletRequest req, HttpServletResponse resp, BindException errors) and call showForm(HttpServletRequest req, BindException errors, String viewName) with whatever view I want.

Java spring link|improve this question edited Apr 17 '09 at 21:02 asked Apr 17 '09 at 20:34Steve Kuo6,3201560113 71% accept rate.

Damn, I was typing and you answered your own question faster :) Good luck to you. It is easy to use once you trace it back to the top - but I wish it was better. I've had no luck with the annotation approach though - it just confuses me, I'd rather program my own controller with the controller interface.

– MetroidFan2002 Apr 17 '09 at 21:12.

I believe SimpleFormController provides two "showForm" protected methods. These can be overridden and the BindException used to retrieve the "target" which is your form object, you can then return a ModelAndView based on any bound form object property. You should also take a look at processFormSubmission, it dictates which methods are called really.

Another method is "isFormChangeRequest" which determines whether or not your form should change - you can use this to set this to true and it will then call showForm with the request, response, etc. and you can then re-examine the request. The only way you'll learn how to use this hierarchy is by examining it. It is not very good - it provides many things, but not very well.

Spring MVC typically has to be extended in order for it to be very useful.

I'd be interested to hear more about what you think the packaged Controllers in Spring MVC don't do "very well". Personally I find them pretty useful as a starting point – matt be Apr 18 '09 at 3:41 They're great as a starting point, but they provide too many protected methods that you have to then trace back to the source of where it is called. Also, if you want to use their controller in a different manner it is difficult to find the side effect.

For instance, I had a form controller that I had to store the form object so that it could redirect to another controller which used the object from the session to display the data - but unbeknonst to me, the form controllers removed the object – MetroidFan2002 Apr 18 '09 at 4:41 ...Now, it does say this on the Javadoc for some methods, but there are so many protected methods it is difficult to find which ones actually need to be used. The hierarchy is simply too complex - that a class with "Simple" in its name extends six classes (ignoring the Object extension), and has probably around 50 methods is rediculous and is a key indicator of bad design. Too much extension, not enough use.

– MetroidFan2002 Apr 18 '09 at 4:43.

I don't think it's doable with SimpleFormController. You could try to stop using the controller hierarchy classes which is about to be deprecated anyway and take a look at annotation based Controllers introduced with Spring 2.5. They allow a much more flexible form handling. Don't be put off if you don't like Auto-injection.

Although none of the examples really make it obvious, you can use annotation driven controllers and define all beans in an XML content.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions