Spring 3 web request interceptor - how do I get a BindingResult?

I really appreciate Spring 3 mappings driven by anonymous web controllers

I have many controllers with signatures such as:

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

But my problem is that I want to write an interceptor that will go through BindingResults after processing - how can I get them from HttpRequest or HttpResponse?

since intercpetor methods have the same signature

public boolean postHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
+3
source share
2 answers

So, with a lot of help from @Axtavt, I came to the conclusion that you can go to Bind reuslt from ModelAndView in the 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);
}
+1
source

BindingResult BindingResult.MODEL_KEY_PREFIX + <name of the model attribute>, . , Hurda, :

request.getAttribute(BindingResult.MODEL_KEY_PREFIX + "solicitation")
+8

Source: https://habr.com/ru/post/1768512/


All Articles