Validating @RequestParam in Spring 3 MVC?

If you are using Spring MVC 3.0 or later, you can use the declarative validation support Spring provides. You would then declare the validation restrictions on the model bean and add the Valid annotation to your form backing bean as described in the chapter Spring Validation in the reference docs.

If you are using Spring MVC 3.0 or later, you can use the declarative validation support Spring provides. You would then declare the validation restrictions on the model bean and add the @Valid annotation to your form backing bean as described in the chapter "Spring Validation" in the reference docs. If you add a BindingResult parameter directly after the bean being validated, you can then check for validation errors in your controller: // .. in the bean class public class MyBean { @NotNull private String name; // .. } // .. in the @Controller public ModelAndView doSomething(@Valid MyBean data, BindingResult bindingResult) { if (bindingResult.hasErrors()) { // back to form } // do something with the bean }.

That is what I'm trying to avoid. I don't want or need another forming back object. – Adam Gent Jul 30 at 18:48 Ah, okay.

Then I don't see the motivation for BindingResult (and the DataBinder used internally) since they apply to binding request data to form/command objects only. If you try to inspect individual @RequestParam values (e. G.

Primitives or Strings), you could use an aspect to pre-fill a custom BindingResult or maybe write a specific HandlerInterceptor who performs additional action on the request parameters before it hits the controller. – Axel Knauf Jul 31 at 11:36 the reason I want use the BindingResult is that it handles error messaging and i18n. For now I just made another transfer object.

– Adam Gent Aug 1 at 13:29.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions