views:

30

answers:

1

In my Spring MVC based web-app, I'm manually creating an Errors/BindingResult object after manually validating one of my domain objects. I can add my domain object into the Model by doing the obvious:

model.addAttribute("myObject", myObject);

After I do validation and have created an Errors/BindingResult object, under which key should I add that to the model?

Note: I can't use the automatic validation provided by @Valid and bind my domain and errors object at the method level. I really do need to know how to do this manually.

+1  A: 

The BindingResult for a given model is added to the model map using keys constructed using a combination of BindingResult.MODEL_KEY_PREFIX and the model name. if you have a dig through the source code (for example in HandlerMethodInvoker.updateModelAttributes()), you can see how it's used.

It's a bit risky, though, this implementation detail may change in future versions of Spring.

skaffman
I take it they don't expose anything a little more fixed in the public API? Aware that this could change in the future (though probably unlikely).
GaryF
@GaryF: Not that I could see, no. You're not really supposed to go poking about in there :)
skaffman