Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring SimpleFormController in 3.0

Tags:

i notice that this controller has now been deprecated in the latest spring and was wondering what the alternative controller is?

like image 916
Jonathan Avatar asked Jan 19 '11 10:01

Jonathan


People also ask

How do I define a simpleformcontroller in spring?

Forms in Spring are typically modelled by extending the org.springframework.web.servlet.mvc.SimpleFormController class, but using Spring annotations, they can also be simplified and defined by the @Controller annotation.Without annotations, a SimpleFormController would be defined as below as in both a Java class and as a bean in XML.

How to handle forms in spring?

to handle forms in spring you need to extend your controller class from simpleformcontroller class. here we will create a user registration form to understand how this works. the simpleformcontroller is deprecated as of spring 3.0 so if you are using spring 3.0 or above use the annotate controllers instead.

Can simpleformcontroller handle more than one request?

Yup SimpleFormController is no longer supported (tried with 4.0.4.RELEASE ). Show activity on this post. In Spring 3.0 you should use simple classes annotated by @Controller. Such controller can handle more than one request. Each request is handled by its own method. These methods are annotated by @RequestMapping.

What is simpleformcontroller in Salesforce?

@Deprecated public class SimpleFormController extends AbstractFormController Concrete FormController implementation that provides configurable form and success views, and an onSubmit chain for convenient overriding. Automatically resubmits to the form view in case of validation errors, and renders the success view in case of a valid submission.


2 Answers

Annotated POJOs can act as controllers; see @Controller.

like image 27
duffymo Avatar answered Dec 14 '22 23:12

duffymo


In Spring 3.0 you should use simple classes annotated by @Controller. Such controller can handle more than one request. Each request is handled by its own method. These methods are annotated by @RequestMapping.

One thing you need to rethink is the fact, that a old school SimpleFormController handle a lot of different requests (at least: one to get the form and a second to submit the form). You have to handle this now by hand. But believe me it is easier.

For example this Controller in REST Style, will handle two requests:

  • /book - POST: to create a book
  • /book/form - GET: to get the form for creation

Java Code:

@RequestMapping("/book/**") @Controller public class BookController {      @RequestMapping(value = "/book", method = RequestMethod.POST)     public String create(         @ModelAttribute("bookCommand") final BookCommand bookCommand) {          Book book = createBookFromBookCommand(bookCommand);         return "redirect:/book/" + book.getId();     }      @RequestMapping(value = "/book/form", method = RequestMethod.GET)     public String createForm(final ModelMap modelMap) {         modelMap.addAttribute("all", "what you need");         return "book/create"; //book/create.jsp     } } 
like image 120
Ralph Avatar answered Dec 14 '22 23:12

Ralph