5 Replies Latest reply on Feb 26, 2008 11:13 AM by blabno

    In(value="selectedCountry",create=true) private Country editedCountry;

    blabno Master
      @In(value="selectedCountry",create=true) private Country editedCountry;

      When bean is invoked, then editedCountry is null !
      Of course there is no selectedCountry in any context.
      This happens only if value is set to something different than editedCountry (so the name of property).

      Following for example works :

      @In(value="editedCountry",create=true) private Country editedCountry;

      I reported JIRA, but issue was rejected. They said this is how it suppose to work. It sounds silly to me. Why component should be created only if it's name is same as value attribute ?

        • 1. Re: In(value="selectedCountry",create=true) private Country editedCountry;
          Nicklas Karlsson Master

          There is usually a motivation for the design choices but at first glance one would think that create=true would guarantee creation. How does auto-create react to your case?

          • 2. Re: In(value="selectedCountry",create=true) private Country editedCountry;
            blabno Master

            This is so bad !
            I've read the code responsible for injection. It will first search context for variable with name matching value or member's name if value is not specified. If nothing is find then it will try to find component with name matching, as above, value or member's name. (all is done in org/jboss/seam/Component.java)

            This is a serious limitation that allows us to have only one member created during injection.

            I would like to have something like this :

            class Sth {
               Country notAComponentName1;
               Country notAComponentName2;

            So there should be an additional attribute in @In annotation like component.

            What do you think Seam developers ? I could write a patch ?

            • 4. Re: In(value="selectedCountry",create=true) private Country editedCountry;
              blabno Master

              I've read reference and 2 other books on seam. It is poorly explained how @In annotation works. At least in examples. I know that at the end in reference in Annotations part you wrote a sentence :

              create — specifies that Seam should instantiate the component with the same name as the context variable if the context variable is undefined (null) in all contexts. Default to false.

              Just know, that it is the only one sentence about it in all reference.

              I think, that my solution, with extending @In annotation is more flexible than adding @Role to a component.

              But, anyway, thank you very much for response.

              • 5. Re: In(value="selectedCountry",create=true) private Country editedCountry;
                blabno Master

                Hey guys, I've extended @In annotation as proposed, and recompiled seam on my machine, and everything rocks.

                --- /mnt/sda5/bernard/original/In.java  2008-02-26 10:12:59.000000000 +0000
                +++ annotations/In.java 2008-02-26 11:04:49.000000000 +0000
                @@ -49,4 +49,13 @@
                     * More efficient as it avoids scanning all contexts
                    ScopeType scope() default ScopeType.UNSPECIFIED;
                +   /**
                +    * Name of component to create if create is set to
                +    * true, and there is no context variable for neither
                +    * value nor member's name, and they both are different
                +    * from component's name.
                +    * @author Bernard Labno
                +    */
                +   String component() default "";

                --- /mnt/sda5/bernard/original/Component.java   2008-02-26 10:12:53.000000000 +0000
                +++ Component.java      2008-02-26 10:38:00.000000000 +0000
                @@ -2163,6 +2163,11 @@
                +      if( result==null && in.create() && in.component()!=null && !in.component().equals("") )
                +      {
                +       result = getInstance(in.component(),true,null);
                +      }
                       if ( result==null && enforceRequired && in.required() )
                          throw new RequiredException(