Issue Details (XML | Word | Printable)

Key: SPR-4978
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Juergen Hoeller
Reporter: Kenny MacLeod
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Spring Framework

@InitBinder can fail when using mix of command objects and plain parameters

Created: 03/Jul/08 10:24 AM   Updated: 07/Aug/08 06:00 AM   Resolved: 07/Aug/08 06:00 AM
Component/s: SpringWEB
Affects Version/s: 2.5.5
Fix Version/s: 2.5.6

Time Tracking:
Not Specified

Issue Links:
Related
 


 Description  « Hide

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.



Kenny MacLeod added a comment - 05/Aug/08 10:52 AM

bump


Juergen Hoeller added a comment - 06/Aug/08 04:06 AM

Thanks


Juergen Hoeller added a comment - 07/Aug/08 06:00 AM

I've relaxed the assertion in our BindingResults, accepting a null target object as far as possible. This should be available in tonight's 2.5.6 snapshot. Please give it a try!

Juergen