2 Replies Latest reply on Feb 21, 2012 8:59 AM by enrix

    To access a EJB within a Converter-Class

    enrix

      Hello Community,

       

      Is ist possible to access a non-interface EJB in a self-made JSF-converter? I have created a JEE6 maven-project and the @EJB annotation within the converter doesn't work. And the InitialContext lookup

      required an interface.

       

      best regards

        • 1. Re: To access a EJB within a Converter-Class
          healeyb

          Henry, it's an annoying oversight that @EJB doesn't work, but you can add something like this in the

          converter constructor:

           

          private YourEjbClass ejb;

           

          public YourConverter() {

                  if (ejb == null) {

                      try {

                          ctx = new InitialContext();

                          ejb = (YourEjbClass) ctx.lookup("java:global/com.myproject_MyProject_war_1.0.0/YourEjbClass");

                      } catch (Exception e) { // poor example of exception handling!

                          Log.log(e.getMessage());

                      }

                  }

              }

           

          The glassfish app server outputs the portable jndi names in the server log at startup time for all ejbs, hopefully similar

          functionality exists for other app servers.

           

          I use Myfaces CODI http://myfaces.apache.org/extensions/cdi/ which allows me to @Inject ejbs into converter

          classes that are annotated with the @Advanced annotation (I think this may depend on whether you're using

          OpenWebBeans or Weld as the CDI implementation, as a glassfish user I use Weld and require @Advanced).

           

          Regards,

          Brendan.

          1 of 1 people found this helpful
          • 2. Re: To access a EJB within a Converter-Class
            enrix

            Brendan, thanks for the helpful answer. For the time i have chosen the InitialContext-Lookup and it works trouble-free. Soon I'll be looking closer for CODI. It should also work in Jboss AS7, but befor i have to change my pom.xml. I have visited your Link an have found maven-build-information in the project summary. Maybe, if you have time, you can provide your code from your pom.xml.

             

            For those how are often reliant on a InitialContext-Lookup, I've got a tip: During the deploy-process the AS shows the right JNDI-Namespaces (java:global/..., java:modul:/..., java:app/...) of your EJB's within the open terminal.

             

            Best regards an good cooperation continues

            Henry