When using Spring’s SimpleFormController
, the default behaviour is to pass reference data to the form view, but not to the success view. However it’s very easy to override this behaviour, and access the reference data from the success view as well.
To do this, override the 4-argument onSubmit
method like this:
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { ModelAndView mav = onSubmit(command, errors); Map refData = referenceData(request, command, errors); mav.getModel().putAll(refData); return mav; }
If you’ve only implemented the 1-argument referenceData
method, don’t worry; the default 3-argument referenceData
just delegates to the 1-argument method, so your implementation will be called.
If you’re interested, you can see the code for SimpleFormController
.
Thanks – just the tip I was looking for!
dito ! thx