views:

96

answers:

2

I realy appreciate Spring 3 anoation driven mapping of Web Controllers

I have a lot of Controllers with signatures like:

@RequestMapping(value = "solicitation/create",method = RequestMethod.POST)
public String handleSubmitForm(Model model, @ModelAttribute("solicitation") Solicitation  solicitation, BindingResult result) 

But my issue is, that I want to write an interceptor that would ho through BindingResults after processing - how do I get them from HttpRequest or HttpResponse?

as intercpetor methods are with alike signature

public boolean postHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
+1  A: 

After execution of controller method BindingResult is stored as a model attribute named BindingResult.MODEL_KEY_PREFIX + <name of the model attribute>, later model attributes are merged into request attributes. So, before merging you can use Hurda's own answer, after merging use:

request.getAttribute(BindingResult.MODEL_KEY_PREFIX + "solicitation")
axtavt
where in the documentation can I find such informations? (I've started with Spring 3.0]
Hurda
@Hurda: Accessing `BindingResult` without standard facilities (such as `<form:errors>` tag) is a rather advanced topic, so placement of `BindingResult` in the model described in its javadoc: http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/validation/BindingResult.html
axtavt
So I just tested that and the BindResult aint in request attributes, but in the model. But that's OK because ModelAndView is part of void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) signature
Hurda
+1  A: 

So with big help from @Axtavt I came to conlusion, that you can get to Bind reuslt from ModelAndView in postHandle method:

void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
  String key = BindingResult.MODEL_KEY_PREFIX + "commandName";
  BindingResult br = (BindingResult) modelAndView.getModel().get(key);
}
Hurda