tbruyelle
tbruyelle

Reputation: 13045

JSR303 : Is it possible to inject arguments to a custom validator at validation time?

I have a custom validator and it need to know the user being validated. How to inject the User object in a custom validator ?

After some search it seems there is no way to do that, maybe it's something no applicable to jsr 303 ?

Upvotes: 2

Views: 298

Answers (1)

Gunnar
Gunnar

Reputation: 19020

This really depends on the framework you're using to perform dependency injection and object wiring.

The Spring framework provides out-of-the-box support for dependency injection within validators since version 3.0. Have a look at the reference guide to learn how to use LocalValidatorFactoryBean.

If you're using CDI, then you might be interested in Seam Validation, a CDI portable injection which provides dependency injection for validators using CDI.

If that not answers your question, an example showing what you're up to do would help.

Upvotes: 1

Related Questions