11 Replies Latest reply on Feb 10, 2010 8:05 AM by Stoyan Petkov

    Outjecting in conversation

    Stoyan Petkov Newbie

      Hi guys,


      I am working on the implementation of a conversation that has three screens. I start a conversation when I arrive on the first screen and close conversation when all the information has been entered by the user in the other two screens. In order to collect information I have a context variable. The variable is initialized in the first screen. It can be initialized from the data base or created. I use @In and @Out annotations in order to access the variable. When the variable is initialized from the database with an existing information every thing works perfect. The problem is when I create a new instance. In this case the instance is created in the last screen. When I go back to a different screen and look at the content of the conversation the environment variable is not there.


      I am sorry to bother every body with this one but it drives me crazy.


      Thanks for your help.

        • 1. Re: Outjecting in conversation
          Tim Evers Master

          How are you creating the new instance.


          Please show your code.


          Thanks.

          • 2. Re: Outjecting in conversation
            Stoyan Petkov Newbie
            In the class where I create the instance I have the following:

            ...
            @Name("consultTpProcessSelectorHome")
            public class TpProcessSelectorHome
              extends EntityHome<TpProcessSelector>
            {
              @In(value="defaultErrorProcess", required=false, scope=ScopeType.CONVERSATION)
              @Out(value="defaultErrorProcess", required=false, scope=ScopeType.CONVERSATION)
              private TpProcessSelector defaultErrorProcess;

            ....

              @Override
                 protected TpProcessSelector createInstance()
                 {
                if (defaultErrorProcess == null)
                  defaultErrorProcess = new TpProcessSelector();
               
                return defaultErrorProcess;
                 }
            ....
            }

            The class that controls the conversation is as follows:

            @Name("inDocConfigBean")
            @Scope(ScopeType.CONVERSATION)
            public class InDocConfigBean
            {
            ....
              @In(value="#{inDocConfigControl}")
              private InDocConfigControl inDocConfigControl;

              @Out(value="defaultErrorProcess", required=false)
              private TpProcessSelector defaultErrorProcess;

            If the defaultErrorProcess is initialized here with a value from the database or is null.

            ...
            }

            It has @Begin and @End methods.

            The context variable is accessed in the second screen as follows:

                   <s:decorate
                          id="errorProcessVersion"
                          template="/layout/display.xhtml"
                          rendered="#{!inDocConfigControl.addDefErrProc()}">
                    <ui:define name="label">Error Process Version</ui:define>
                    <h:outputText value="#{inDocConfigBean.inDocConfigControl.defaultErrorBusinessProcess.bpProcessDefinitions.id.processVersion}"/>
                  </s:decorate

            For the InDocConfigControl I have

            @Name("inDocConfigControl")
            public class InDocConfigControl
              extends EntityQuery<TpSearchMethodXref>
            {
            ...
              @In(value="defaultErrorProcess", create=false, required=false)
              @Out(value="defaultErrorProcess", required=false, scope=ScopeType.CONVERSATION)
              private TpProcessSelector defaultErrorProcess;
            ...
              public TpProcessSelector getDefaultErrorBusinessProcess()
              {
                return defaultErrorProcess;
              }
            ...
            }

            Sorry if the snippets are not full, but the code is in several Java files and JSF pages.
            • 3. Re: Outjecting in conversation
              Tim Evers Master

              Stoyan Petkov wrote on Feb 10, 2010 02:23:


              @Override
              protected TpProcessSelector createInstance() 
              {
                  if (defaultErrorProcess == null)
                  defaultErrorProcess = new TpProcessSelector();
                  return defaultErrorProcess;
              }
              





              You can't use the new operator to construct a new instance of Seam beans.
              Instead use Component.getInstance(TpProcessSelector.class, true)


              Hope that helps.

              • 4. Re: Outjecting in conversation
                Stoyan Petkov Newbie

                In fact every thing is fine if in the case of a new instance in the InDocConfigBean I create an empty defaultErrorProcess. It gets populated with data on its on screen and it is in the conversation. The problem is when the value is null. I understand that in this case nothing gets put in the conversation, but I would expect that when the object gets created later in the conversation the value to be outjected to the conversation. I would be interested to know if I am doing something not right or that how the behavior is designed to work. I can supply more code snippets if needed.

                • 6. Re: Outjecting in conversation
                  Tim Evers Master

                  Did you try what I said or not?

                  • 7. Re: Outjecting in conversation
                    Tim Evers Master

                    Nevermind.... didn't get your reply till just then :S

                    • 8. Re: Outjecting in conversation
                      Stoyan Petkov Newbie

                      Thanks for the suggestion. TpProcessSelector is not a Seam component. In order to test my scenario I use new TpProcessSelector in the case when I do not have data in the database. I have the object created in inDocConfigBean. In this case I can see the variable outjected to the conversation.


                      I have noticed that inDocConfigBean has @Scope conversation, but TpProcessSelectorHome does not. Is it posible this to have an effect on the outjection process.

                      • 9. Re: Outjecting in conversation
                        Adrian Mitev Master

                        If you don't specify outjection scope explicitly, the scope of the component owning the reference is used.

                        • 10. Re: Outjecting in conversation
                          Stoyan Petkov Newbie

                          So you are saying that in the case of creating the defaultErrorProcess instance in the InDocConfigBean it gets outjected in the conversation because of the @Scope annotation?

                          • 11. Re: Outjecting in conversation
                            Stoyan Petkov Newbie

                            I have solved the problem by creating a non initialized defaultErrorProcess instance in the InDocConfigBean and outjecting it in the conversation. Then I inject it when I want to add or change the information.


                            My original idea for the case when the data is not present in the database to create the instance when the user enters the information, but I could not get the instance outjected to the conversation.


                            Still can not understand why?


                            Thanks for all the help.