Doing a redirect to GET after POST.
Spring Web should be adding the ‘clientId’ model attribute below onto my URL, but it’s not….
@Override
protected ModelAndView onSubmit(Object command, BindException errors) throws Exception {
ClientID clientId = ((MyCommand) command).getClientId();
return new ModelAndView(new RedirectView(getSuccessView()), "clientId", clientId);
}
The same problem occurs if I just pass getSuccessView() to the ModelAndView and put redirect:<success_view_url> as the success view in my config.
The problem is that, by default,
RedirectViewonly commutes what it calls ‘Simple Value Types’ to the URL. c.f.RedirectView.isEligibleValue().The solution is to add the
ClientIdto the model as aStringrather than the more custom type:Note
.toString()on the last line.You can override
isEligibleValue()(on your ownRedirectViewsubclass) is you really want to, but it’s easier to just toString everything you put in there.