PDA

View Full Version : Help with programmatic setting formView and successView


adcspring
Oct 11th, 2005, 11:00 AM
Our website contains various layouts for different sub-sites. For example, the main website will have layout "core" at www.domain.com but various sub-sites like www.domain.com/subsitea and www.domain.com/subsiteb will both share a different layout "subsite".

However, across the various sites we have, are forms. The form logic is for all intents and purposes the same. Yet in Spring I am forced to declare mappings from URLs to form views and form success views.

This is really inefficient for us. We'd much rather somehow programmatically configure formView and formSuccess (and also the validator) per request based on a model object property that we have in the request.

Can anyone tell me if it is possible to programmatically change form view and success view prior to a request?

I tried changing it in onBind but Spring therw an error that my SimpleFormController did not define formView and formSucess.

Thanks

cmgharris
Oct 12th, 2005, 03:46 AM
The javadoc shows setFormView() and setSuccessView() methods for SimpleFormController, so you should be able to set them using these methods. NB successView, not formSuccess.

What was your error?

adcspring
Oct 12th, 2005, 04:22 AM
I, yes I am aware of these injector methods but I don't think you can call them at all stages of a request workflow. The earliest time i could find to try them out was onBind right at the start of form workflow. however, spring threw an exception that (I do not have the precise stacktrace) said the formView and successView were unset, meaning my effort to code them in did not work.

I have since decided that for our needs with forms Spring introduces too much configuration. Now don't get me wrong Spring is superb and really good for forms that are sure things like in applications, or perhaps you have 1 contact form, but we're faced with a marketing dept. that creates forms like there's no tomorrow and they all vary so that an object model representation is nigh on impossible.

Therefore I am writing my own FormController that will (classically) examine the form parameter map. Each element will be named in such a way that a validation rule is specified. I will then validate using Commons Validator or similar and control sending the form back and re-binding input fields to the errors or moving to a success page.

This gets around having to write URL mappings, it gets around having to worry about setting form view and success, it gets around creating comand object hierarchies and it gets around writing validators.

Although it pains me to do it this way (a la PHP, ASP) there is no elegant alternative that does not involve creating classes and therfore restarting the server just for a form.

mindjoy
Oct 13th, 2005, 08:01 AM
...you can use setFormView() and setSuccessView in the SimpleFormController subclass constructor.

adcspring
Oct 13th, 2005, 08:14 AM
omg read the frickin post thread!!!!!