In a Spring MVC application I have a model with a
There are few solutions for this problem available on the internet but none of those which I found was clean and simple enough. There has been some request interceptors, List interface custom implementations, etc.
Thanks to Thymeleaf's fragments there is only one template needed. By default, on an HTTP request all endpoints returns whole page. If Ajax request is sent, smaller part of the page containing the list will be returned.
Ability to not to re-render whole page on every HTTP request makes user experience more seamless. Following jQuery snippet will a) call the endpoints for adding or removing inems from list and b) replace
#items fragment by returned content.