1 Reply Latest reply on Feb 3, 2011 11:38 AM by monkeyden

    Problem with Stateless bean injection

    wankes2000

      Hello i have a lot of problem to call a stateless ejb from a seam action components y always obtain bean not bound exception.
      Here is mi action code:




      package org.domain.tmepgv2.session;
      
      import java.util.List;
      
      import org.domain.tmepgv2.entity.InputsOutputs;
      import org.domain.tmepgv2.entity.Pluggin;
      import org.domain.tmepgv2.helpers.InputMenuBean;
      import org.domain.tmepgv2.helpers.InputMenuLocal;
      import org.domain.tmepgv2.ws.WebserviceEpgCoreBean;
      import org.domain.tmepgv2.ws.WebserviceEpgCoreLocal;
      
      
      import org.jboss.seam.Component;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      
      @Name("inputMenu")
      public class InputMenu
      {
         
      
          private Pluggin pluggin;
          private List<InputsOutputs> lista;
          /**
           * @return the lista
           */
          public List<InputsOutputs> getLista()
          {
              return lista;
          }
      
          /**
           * @param lista the lista to set
           */
          public void setLista(List<InputsOutputs> lista)
          {
              this.lista = lista;
          }
      
          /**
           * @return the listaPluggins
           */
          public List<Pluggin> getListaPluggins()
          {
           InputMenuLocal action = null;
           
           
           
           action = (InputMenuLocal) Component.getInstance(InputMenuBean.class);
           return action.getInputPluggins();
          }
      
          /**
           * @param listaPluggins the listaPluggins to set
           */
          public void setListaPluggins(List<Pluggin> listaPluggins)
          {
              this.listaPluggins = listaPluggins;
          }
      
          private List<Pluggin> listaPluggins;
          
          
              
           
           
           
           
           
          
      }



      And my bean code:




      package org.domain.tmepgv2.helpers;
      
      import java.util.ArrayList;
      
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.NoResultException;
      
      import org.domain.tmepgv2.entity.InputsOutputs;
      import org.domain.tmepgv2.entity.Pluggin;
      
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      @Stateless
      @Name("inputMenuEJB")
      public  class InputMenuBean implements InputMenuLocal
      {
          @In EntityManager entityManager;
      
          
          
          public ArrayList<Pluggin> getInputPluggins()
          {
           try
           {
           ArrayList<Pluggin> pluggin = (ArrayList<Pluggin>) entityManager.createQuery(
      
               "from Pluggin where tipo = :tipo")
      
               .setParameter("tipo", 1).getResultList();
           return pluggin;
           }
           catch (NoResultException e)
           {
               return new ArrayList<Pluggin>();
           }
               
          }
          public ArrayList<InputsOutputs> getInputs()
          {
           try
           {
           ArrayList<InputsOutputs> inputs = (ArrayList<InputsOutputs>) entityManager.createQuery(
      
               "from InputsOutputs where tipo = :tipo")
      
               .setParameter("tipo", 0).getResultList();
           
           return inputs;
           }
           catch (NoResultException e)
           {
               return new ArrayList<InputsOutputs>();
           }
          }
          public void filterByPluggin()
          {
           // TODO Auto-generated method stub
           System.out.println("Prueba");
          }
      }
      



      My components.xml is with @jndiPattern@ default configuration and y have a ejb-jar.xml like this:




      <?xml version="1.0" encoding="UTF-8"?>
      <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" version="3.0">
          
          <interceptors>
              <interceptor>
                  <interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
              </interceptor>
          </interceptors>
          <assembly-descriptor>
              <interceptor-binding>
                  <ejb-name>*</ejb-name>
                  <interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
              </interceptor-binding>
          </assembly-descriptor>
          
      </ejb-jar>
      



      What is wrong? Sorry about my poor english.






        • 1. Re: Problem with Stateless bean injection
          monkeyden

          Inject it by name, rather than class:


          action = (InputMenuLocal) Component.getInstance("inputMenuEJB");
          



          I normally use POJOs but, IIRC, I don't think you're getting a InputMenuBean, but a proxy which implements InputMenuLocal.  Also, be sure that it's interface (InputMenuLocal) is annotated with @Local, which I assume it is by your choice of interface name. 


          I've also made the mistake of not including the bean's public methods in the interface.  :)