Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@SessionAttributes with a Validator set up using @InitBinder

 
Ali Cameron
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: http://puretech.paawak.com/2010/09/05/annotation-based-spring-mvc-how-tos/ 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic