-->
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.  [ 2 posts ] 
Author Message
 Post subject: custom MessageInterpolation and CDI
PostPosted: Mon Mar 11, 2013 5:25 am 
Newbie

Joined: Thu May 01, 2008 7:21 am
Posts: 1
Hi,

I am working in a Java EE (JBoss AS 7) environment and I need to inject some objects into a custom MessageInterpolator. Is this possible with Hibernate Validator (I am using HV 4.2.0) ?


Top
 Profile  
 
 Post subject: Re: custom MessageInterpolation and CDI
PostPosted: Mon Mar 11, 2013 4:15 pm 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi,

This will be possible out of the box with Bean Validation 1.1 and Hibernate Validator 5 (to be released soon).

For now you could configure your custom interpolator using CDI (e.g. by having it injected into a CDI bean) and pass it when bootstrapping a validator:

Code:
@ApplicationScoped
public class ValidatorProducer {

    @Inject
    private MessageInterpolator interpolator;

    @Produces
    public Validator createValidator() {
        Configuration<?> configuration = Validation.byDefaultProvider().configure();
        ValidatorFactory factory = configuration
            .messageInterpolator( interpolator )
            .buildValidatorFactory();

        return factory.getValidator();
    }
}


--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.