-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Using InjectingConstraintValidatorFactory
PostPosted: Tue Apr 18, 2017 7:37 pm 
Newbie

Joined: Sat Mar 17, 2012 1:33 pm
Posts: 7
Hi,

In Resteasy, we call

Code:
ValidatorFactory.class.cast(context.lookup("java:comp/ValidatorFactory"));


to get a CDI aware ValidatorFactory. Recently, we have had a request to support Validation and CDI in Java SE, and I can get an instance of InjectingConstraintValidatorFactory by calling
Code:
                  HibernateValidatorConfiguration config = Validation.byProvider(HibernateValidator.class).configure();
                  ConstraintValidatorFactory cvf = null;
                  try
                  {
                     Class<?> cvfClass = config.getClass().getClassLoader().loadClass("org.hibernate.validator.internal.cdi.InjectingConstraintValidatorFactory"); 
                     if (cvfClass != null)
                     {
                        BeanManager beanManager = CDI.current().getBeanManager();
                        Constructor<?> constructor = cvfClass.getConstructor(BeanManager.class);
                        cvf = (ConstraintValidatorFactory) constructor.newInstance(beanManager);
                        validatorFactory = tmpValidatorFactory = config.constraintValidatorFactory(cvf).buildValidatorFactory();
                     }
                  }

Is there a more elegant, safer way of doing that, maybe by way of a different call to Validation.byProvider()?

Thanks,
Ron


Top
 Profile  
 
 Post subject: Re: Using InjectingConstraintValidatorFactory
PostPosted: Wed Apr 19, 2017 12:04 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I think you should ask this question in the Validator forum as this class belongs to the Hibernate Validator project.


Top
 Profile  
 
 Post subject: Re: Using InjectingConstraintValidatorFactory
PostPosted: Wed Apr 19, 2017 11:22 am 
Newbie

Joined: Sat Mar 17, 2012 1:33 pm
Posts: 7
Ah, thanks, vlad. I didn't realize that there was a separate forum for Validator. Done.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.