Is it possible to @Inject
into a validator in WebSphere?
We would like to validate against values in the database.
There is code from here IBM's site which details how to obtain a validator.
Context context = new InitialContext();
ValidatorFactory validatorFactory = (ValidatorFactory)context.lookup("java:comp/ValidatorFactory");
Validator validator = (Validator)context.lookup("java:comp/Validator");
But this does not allow you to inject classes, there is no error but the injected items classes are null, so it is likely not in a proxied context.
Alternatively we can create statically using this, but of course this fails too, it is not CDI aware:
private static final Validator validator = Validation.byProvider(ApacheValidationProvider.class).configure().buildValidatorFactory().getValidator();
Is there a clean solution to get this working?
Aucun commentaire:
Enregistrer un commentaire