4 Replies Latest reply on Aug 23, 2007 6:40 AM by Alex Ka

    How are @In(create = true) and @Name connected?

    Alex Ka Novice

      In the application I work on all entity beans had an @Name. I considered this unnecessary and removed it.

      I tested the application and on one page an NPE occured. It was complaining that a field with @Out had a null value. This field is declared like this:

      @In(required = false, create = true)
      ExamData examData;

      As it turns out, if the ExamData entity has @Name the "create" attribute of @In works and otherwise not. Can someone explain to me what is happening?

        • 1. Re: How are @In(create = true) and @Name connected?
          Francis LIMOUSY Newbie

          Mmm, first @Out complains about nullity because you didn't specify that it wasn't required (required=false).
          This means the outjected value must not be null

          About the @Name, if I understand your question, the link is done on the var name.
          If you inject ExamData examData; Seam will look for "examData" in the contexts.
          If you specify that you want to look for myExamData for example, it's done like this:


          • 2. Re: How are @In(create = true) and @Name connected?
            Alex Ka Novice

            Yes, @Out needs a not-null value and this is why I added create=true.

            My question is why does the creation depend on whether I have @Name or not.

            BTW Is there a case in which problems arise from having @Name("examData") and a field @In @Out ExamData examData?

            • 3. Re: How are @In(create = true) and @Name connected?
              Pete Muir Master

              @Name registers your class as a Seam component. If you don't put @Name on it and @In it, then you need to provide another way of instantiating e.g. a factory.

              • 4. Re: How are @In(create = true) and @Name connected?
                Alex Ka Novice

                Thanks for the explanation. It has helped me turn my attention on the In annotation. Here is what the javadoc states:

                 * Specifies that a component should be instantiated
                 * if the context variable is null.
                 boolean create() default false;

                and have a look at Component.java
                private static Object getInstance(String name, boolean create, Object result)

                where it is said that:
                 if (result==null && create)
                 result = getInstanceFromFactory(name);
                 if (result==null)
                 if (component==null)
                 //needed when this method is called by JSF
                 if ( log.isDebugEnabled() ) log.debug("seam component not found: " + name);

                And here it is:
                2007-08-23 13:26:51,459 DEBUG [org.jboss.seam.Component] seam component not found: examData

                I understand it better now.