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, RedirectView
only commutes what it calls 'Simple Value Types' to the URL. c.f. RedirectView.isEligibleValue()
.
The solution is to add the ClientId
to the model as a String
rather than the more custom type:
@Override
protected ModelAndView onSubmit(Object command, BindException errors) throws Exception {
ClientID clientId = ((MyCommand) command).getClientId();
return new ModelAndView(new RedirectView(getSuccessView()), "clientId", clientId.toString());
}
Note .toString()
on the last line.
You can override isEligibleValue()
(on your own RedirectView
subclass) is you really want to, but it's easier to just toString everything you put in there.
精彩评论