views:

324

answers:

1

With spring MVC, do you have to use one of the special form controllers or it just makes things easier?

I want to create a form, which doesn't directly map 1:1 to a particular entity, and perform server side validation on them data.

For the front end, I want to use jQuery. Does spring tie itself to a particular javascript library or can I use jquery?

+1  A: 

With Spring MVC 2.5 and newer, you can use annotations to make any class into a controller, without inheriting from one of the form controllers. In fact, the Spring folks are recommending the annotation-based approach and it seems clear that the future of Spring is annotations. In fact, most things that the form controllers do can easily be done with annotations, so using the built-ins doesn't necessarily make anything easier.

If you want to use the built-in Spring binding, where a particular form field maps directly to a particular entity property, you do need to have a single "command" object as your form-backing object. It sounds like this may not work for you; one approach is to have a primary entity be your form-backing object and handle fields that don't map to it as regular request parameters. In this scenario you'd have to put the data for those other entities in via specific code, and then call the validation yourself.

Lastly, no, Spring MVC doesn't tie itself to a JS library, and yes, I've often used jQuery with Spring MVC.

JacobM