views:

2885

answers:

2

Hi, I read few books on spring2.5 on these topic, but still cannot grab the concepts when to use @initBinder. can anyone share any reference or explain in what situation i can use this on web application? How propertyEditor relate to it?

+2  A: 

Well I can't really put it any better than the books, but if your controller has any public methods annotated with @InitBinder, then these methods will be called by the container just before each request is processed, passing in the WebDataBinder being used by the framework.

The most common reason to do this is when you want to customise the way that Spring tries to bind request parameters on to your model, for example if your model has custom datatypes that Spring can't handle out of the box. You register your PropertyEditors against the WebDataBinder. A trivial example would be if you use the JodaTime library in your model, and you want to bind timestamp strings on to a Joda DateTime object.

With Spring 2.0, you use to have to override the protected initBinder() method from the controller superclass, but Spring 2.5 removes the need to do that, you can just use annotations now.

skaffman
A: 

It require Spring 2.5.1+ see https://jira.springsource.org/browse/SPR-4182

Valeri Shibaev