You might be able to use your own Guice-aware interpolator. I haven't tried to code this, so I may be totally wrong, but as you don't control object instantiation, you might need to make the Provider an ugly static field somewhere.
Alternatively, you could configure the Validator and (perhaps) EntityManagerFactory programmatically. The last thing I can think of is that the JPA 2 spec provides a mechanism for this. Any injection it uses would probably be based on CDI, though. Also, Guice-Persist is long-unmaintained and riddled with bugs, I wouldn't recommend using it. On Apr 2, 2014 12:50 AM, "Alex Wood" <[email protected]> wrote: > Hi, > > The web application I work on uses Guice and the JpaPersistModule. We are > also attempting to use JSR 303 Bean Validation with Hibernate Validator. > We would like to provide a custom class (A MessageInterpolator) to look up > messages based on the Accept-Language header of the user's request. This > customization appears to be a common one [1]. We have a Guice Provider > that reads the locale off the ServletRequest and returns the correct > resource bundle. However, I cannot figure out how to have Guice > successfully inject the Provider into the MessageInterpolator. The class > of the MessageInterpolator is defined in META-INF/validation.xml and as far > as I can tell, the creation of the ValidatorFactory class (and the included > MessageInterpolator) occurs within a Hibernate Event Listener that can be > defined in persistence.xml [2]. > > Does anyone have any experience with getting @Injects to work on items > created by JPA as it is getting started? I'd either like to inject > dependencies directly into our own MessageInterpolator or create our own > event listener, but I'm not sure how to get injections run on the > listener. The JpaPersistModule is final so I don't have the option of > binding our event listener in it. > > [1] > https://community.jboss.org/wiki/HowToInterpolateMessagesUsingTheClientLocale > [2] > http://docs.jboss.org/hibernate/validator/4.3/reference/en-US/html_single/#d0e3096 > -------- > Regards, > Alex > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/google-guice. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-guice. For more options, visit https://groups.google.com/d/optout.
