3 Replies Latest reply on Oct 6, 2011 6:54 AM by Corey-James Miller

    Seam component not being injected

    Corey-James Miller Newbie

      I have an element 'Contact' i want injected in my RegisterContact class, but the injection isn't working. The component is 'null'.

      From the following code snippet, you can see I've called Component.getInstance, which obviously isn't injection, but it's shown that my component is in context and accessible with data.
      Can someone provide some guidance please....

      I am only just starting off with Seam, so I may be making some rookie mistakes, I just don't know where to look.

      public class RegisterContact implements Register{
              private Contact contact;
              private EntityManager em;
              private Log log;
              public String register(){
                      contact = (Contact) Component.getInstance("contact");
                      List<Contact> existing;
                      existing = em.createQuery("select firstname from Contact where firstname=:firstname")
                      if ( existing.size() == 0 ) {
                              return "/registered.xhtml";
                      FacesMessages.instance().add("A user with the name #{contact.firstname} already exists");
                      return null;

        • 1. Re: Seam component not being injected
          Aldo Bonzi Novice

          @In does not create the component by default, it just inject what is in a specific context. If you need to create the component at injection time you can do it either by specifying create=true in the @In, or annotating the injected component with @Autocreate

          • 2. Re: Seam component not being injected
            Corey-James Miller Newbie

            The component is in context, I can see it in JBoss debug and if it weren't the following call would fail, wouldn't it?

               contact = (Contact) Component.getInstance("contact");

            As for the create=true option, I don't want seam to create a new Contact component if it can't find one in context, in this case.

            • 3. Re: Seam component not being injected
              Corey-James Miller Newbie

              Seems I was missing the ejb-jar.xml file

              "<?xml version="1.0" encoding="UTF-8"?>
              <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" 
                       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"