6 Replies Latest reply on Oct 16, 2007 8:34 AM by Mohammad Norouzi

    @Unwrap question

    Ning Zhao Apprentice

      Hi folks,

      I would like to use the @Unwrap annotation in an APPLICATION scoped dataStore bean. This stateless bean mainly caches the read-only static data which would be used in the application. I'd like to learn more detail about the @Unwrap than which are already presented in the reference manual. (I build a new Seam dist everyday from the CVS, so my reference manual is always the latest.)

      Here are my questions:

      1. What's the difference between @Factory and @Unwrap in the following two code fragments? (from reference section 3.8)

      public List<Customer> getCustomerList() {
       return ... ;

      public class CustomerListManager
       public List<Customer> getCustomerList() {
       return ... ;

      The reference says

      A manager component is any component with an @Unwrap method. This method returns the value that will be visable to clients, and is called every time a context variable is referenced.

      Doesn't the method in first code fragment with the @Factory annotation also return a List? Is it not visible to clients?

      2. The reference says:

      An even more powerful pattern is the manager component pattern. In this case, we have a Seam component that is bound to a context variable, that manages the value of the context variable, while remaining invisible to clients.

      What does the manager component here exactly manage? And in which situation/context is this manager component pattern bestly used? I looked at the HenHouse example, it seems useful when dealing with events which would cause value changes in the managed list.

      Many thanks in advance for any enlightenment!


        • 1. Re: @Unwrap question
          Richard Leherpeur Novice

          As far as I know, one difference is the way you are going to access your object.

          If you use @Factory, you'll have to access it through the bean: #{myBeanName.myMethodName} (any first reference to myBeanName will trigger a call to the factory method)

          Using unwrap, you directly use the bean name: #{myBeanName} (the bean and any other methods remain hidden, only the result of the unwrap method is exposed).

          There might be other differences, but I'm not aware of them...

          • 2. Re: @Unwrap question
            Wolfgang Schwendt Newbie


            "enzhao" wrote:
            Hi folks,

            1. What's the difference between @Factory and @Unwrap in the following two code fragments? (from reference section 3.8)

            the Factory method gets only called if the referenced context variable, the factory method is defined for, is not yet bound to a value. In your case the context variable is "customerList". Once this context variable is set to a value, the factory won't be called anymore, when "customerList" gets referenced additional times.

            In contrast, the method annotated with @unwrap gets called EVERY time the manager component with the name "customerList" is referenced.

            • 3. Re: @Unwrap question
              Pete Muir Master

              @Factory is useful to populate a context variable that is unchanging, or the change originates within your context. within it's scope (for example a list of hotels available to book). @Unwrap is useful if the variable can change outside your control (e.g. from another users conversation)

              • 4. Re: @Unwrap question
                Ning Zhao Apprentice

                Thanks to you all! :-)


                • 5. Re: @Unwrap question
                  Marius Oancea Novice

                  As I know, @Unwrap annotate methoid is called everytime you access customerList variable. @Factory annotated method gets called only one time (if variable is not yet initialised)

                  • 6. Re: @Unwrap question
                    Mohammad Norouzi Novice

                    Hi all
                    I have a question about @Unwrap.
                    I tried @Unwrap in a test application and as I understood, the whole bean will play on behalf of the wrapped context variable.
                    for instance if I have method

                    class MyBean {
                     public User getUser(){

                    the "bean" is referring to an instance of type User, isn't it?

                    but the thing I want to know is if the values inside a page is changed by the user and press submit button, Are these new changes visible at the server side? for example, the user changes his address which is a property of class User, will this change being applied at context variable inside the MyBean?