This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Author

@SessionAttributes with a Validator set up using @InitBinder

Ali Cameron
Greenhorn

Joined: Oct 16, 2006
Posts: 2
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

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: 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: @SessionAttributes with a Validator set up using @InitBinder
 
Similar Threads
on submit, model object returning null
Validation is not working in Annotaion based controller
@Controller annotation query
How can we make more than one Validator in one Controller Spring3
JSF, strange form action generated