I have a @Controller which has a mix of @RequestMapping methods, some of which use command objects, some of which use plain @requestParam arguments. I also have an @InitBinder method, which calls initDirectFieldAccess() on the WebDataBinder. This obviously only makes sense in the context of the command-object methods, but there's no way to make that distinction in the annotation.
When invoking the methods which declare command object parameters, all is well. However, when invoking the methods which use plain parameter arguments, the @InitBinder method is still called and fails on initDirectFieldAccess
java.lang.IllegalArgumentException: Target bean must not be null
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.validation.DirectFieldBindingResult.<init>(DirectFieldBindingResult.java:51)
at org.springframework.validation.DataBinder.initDirectFieldAccess(DataBinder.java:191)
I suggest that DataBinder be made aware that if its targetBean is null, then do not try and create the DirectFieldBindingResult, since it makes no sense in that context.
The easy workaround is to check in the @InitBinder method that the binder's target bean is non-null before calling initDirectFieldAccess(), but it would be nice if the mechanism was robust enough to catch this case automatically.
bump