1 Reply Latest reply on Dec 7, 2013 6:40 AM by bhanu246

    How To Access Seam Components jar of an ear file in Another Ear by using @In annotation

    ramaraomtech810

      hi to all,

       

       

      i am trying to access seam components of an ear  file in another ear,

       

      i just export the components as jar and add the new seam project by adding that jar files through buildpath and try to inject those components by using @In a null pointer exception raised. Please give me some solution as early as possible.

       

       

       

      here is the code of CommonActor.java which added in jar

       

      package org.itoms.common;

       

      import static org.jboss.seam.annotations.Install.APPLICATION;

       

       

      import org.jboss.seam.Component;

      import org.jboss.seam.ScopeType;

      import org.jboss.seam.annotations.Install;

      import org.jboss.seam.annotations.Name;

      import org.jboss.seam.annotations.Scope;

      import org.jboss.seam.annotations.intercept.BypassInterceptors;

       

      @Name("CommonActor")

      @Scope(ScopeType.CONVERSATION)

      @Install(precedence=APPLICATION,value=true)

      @BypassInterceptors

      public class CommonActor {

          public int add(int a,int b)

          {

              int c=a+b;

              return c;

          }

         

           

             public static CommonActor instance()

             {

                Component component = Component.forName("CommonActor");

                if(component != null && !component.getScope().isContextActive())

                {

                   throw new IllegalStateException("No active "+component.getScope().name()+" context");

                }

                //Attempting to get the instance anyway for backwards compatibility with some potential hack situations.

                return (CommonActor) Component.getInstance("CommonActor");

             }

      }

       

       

       

       

      and i am trying to inject using @In it in a new project as

       

       

       

      @Name("bookingAction")

      @Stateful

      @Scope(ScopeType.SESSION)

      public class BookingAction implements BookingInterface {

       

          @PersistenceContext(type = PersistenceContextType.EXTENDED)

          private EntityManager em;

       

          @In

          private FacesMessages facesMessages;

         

          //@In

          //private CommonActor com;

       

          @In

          private Events events;

         

          @In(create=true,required=false)

          CommonActor com;//=(CommonActor) Component.getInstance("org.itoms.common.CommonActor");//=new CommonActor();

       

      @Factory

      public void getBookingList()

          {

              System.out.println("Page Enter Method.........................................................");

              System.out.println("==============================="+com.add(12, 25));

           }

      }

       

       

      i am getting

       

      atalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446) java.lang.Thread.run(Thread.java:662)

      Caused by java.lang.NullPointerException with message: ""

      org.domain.rorodesign.session.BookingAction.getBookingList(BookingAction.java:129) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112) org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166) org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44) org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56) org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28) org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77) org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) org.jboss.seam