The moose likes Spring and the fly likes @SessionAttributes with a Validator set up using @InitBinder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "@SessionAttributes with a Validator set up using @InitBinder" Watch "@SessionAttributes with a Validator set up using @InitBinder" New topic

@SessionAttributes with a Validator set up using @InitBinder

Ali Cameron

Joined: Oct 16, 2006
Posts: 2

If we configure a validator using @InitBinder and also use @SessionAttributes in Spring 3, Spring will treat @SessionAttributes object as the target of the validator so the code doesn't work. Does anyone know how to get around it? Thank you!

Here is an example. It will throw java.lang.IllegalStateException: Invalid target for Validator [AccountValidator@1cd2d49]: Me

Paul- Phoenix

Joined: Jan 17, 2012
Posts: 1
I think you have to make a previous check to the binder, before to assign the preferred validator, to avoid the IllegalStateException.

I've based on this example: which seems to be quite complete.

I have coded my own validator which implements org.springframework.validation.Validator interface and thus, overrides the supports(...) and validate(...) methods.

and that's my initBinder method, using the validator.supports method instead of check the instanceof the form to be validated.
I also add a CustomEditor to my binder to get my dates formatted.

I'd prefer to use

I'm starting with Spring too but I hope this could help you.
jQuery in Action, 3rd edition
subject: @SessionAttributes with a Validator set up using @InitBinder
It's not a secret anymore!