Passing reference data to the success view

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);
    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.

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

2 Responses to Passing reference data to the success view

  1. nsrmbo says:

    Thanks – just the tip I was looking for!

  2. orx says:

    dito ! thx

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s