2 Replies Latest reply on Apr 10, 2012 2:33 AM by pascal salg

    Getting EntityManager in FacesValidator

    pascal salg Newbie

      Hope i'm not asking a question already answered (at least I couldn't find any)


      I am writing a JEE 6 webapp with Seam 3.1, JSF 2 (Richfaces 4.1) running on JBoss 7.1 final.


      For the past few hours I was trying to get an EntityManager injected into a FacesValidator like this:



      public class ValidatorUsernameReg implements Validator {



      private EntityManager em;




          public void validate(FacesContext arg0, UIComponent arg1, Object arg2)

                  throws ValidatorException {






      I need the EntityManager here to check if a username entered in a registration form already has been taken and then display a corresponding error message.


      But, and that's my problem, the EntityManager always turns out null.


      Is there a way other than creating a corresponding Session Bean which queries the database?

      Is persistence-related stuff not allowed / not possible in JSF Validators?


      Greetings from Germany,