The project downloadable below is an answer to a question repeated in this blog (Spring 3 MVC – Adding Objects to a List element on the fly at form submit – (Generic method))
“How can I submit nested lists of objects?”
The answer is AJAX and JSON.
A very good approach to this is with AngularJS and Spring as demonstrated here.
When the page loads it makes an AJAX call to the server to fetch the model.
The model is bound on the page using AngularJS.
The controls (buttons and input fields) on the page allow the model to be edited.
The model can then be sent to the server via AJAX where it can be persisted. The updated model is returned to the client where it is again bound using angularJS.
The application looks like this
This is a Maven project so just navigate to it using your IDE, open it and run it.
This blog demonstrates how to process JSON using Spring 4 Web MVC.
Spring uses Jackson for JSON parsing. Jackson is configured to ignore extra JSON properties that do not match properties of the bean being populated at the @Controller request end-point method.
This blog demonstrates populating complex objects n levels deep thus overcoming some difficulties encountered as per many of the comments in this blog.
This provides for:
- A far better user experience as there is no page load. Feedback is immediate.
- Ease of development
- Ease of validation handling
- Support for complex forms
- Code portability (think HTML5 clients and single page applications)