11 Replies Latest reply on Aug 3, 2009 8:44 AM by Prathamesh Gaddam

    Doubt: Conversation?

    Prathamesh Gaddam Novice
      Dear team,

      As per Seam Reference it states:
      ' For  entity  beans  and  stateful  session
      beans, the default is CONVERSATION. For JavaBeans, the default is EVENT.'

      Will the conversation be LRC OR temporary conversation(on page load)? If I use the code (with no begin and end conversation):

      HitCounter.page.xml
      <page view-id="/HitCounter.xhtml">
          <begin-conversation join="true" />
      </page>

      HitCount.java
      @Name("hitCount")
      public class HitCount{.. }

      Thank you in advance!
        • 1. Re: Doubt: Conversation?
          Israel Fonseca Apprentice

          In that example of yours the component don't have the Statefull annotation, so it's a JavaBean and the default scope is set to event, no conversations here. If you put a @Statefull, it's going to be a long-running one, because you told so in the page.xml.


          If you still have doubts, just ask it. :)


          • 2. Re: Doubt: Conversation?
            Arbi Sookazian Master

            That's not correct actually.  Your Seam component does not need to be an EJB to be included in a LRC.


            In a Seam app, you can definitely use @Begin and @End, for example, in a JavaBean that is conversation-scoped.


            The example JavaBean above would need something like @Scope(ScopeType.CONVERSATION) at the type (class) level.


            The Seam container uses a temporary conversation for a component unless the temp conversation is promoted to LRC via @Begin, <begin-conversation>, or programmatically via


            Conversation conversation = Conversation.instance();
            conversation.begin();



            or the component joins the active LRC via @Begin(join=true) if an active LRC exists...

            • 3. Re: Doubt: Conversation?
              Israel Fonseca Apprentice

              Ops, sorry if what I told seemed to mean that. What i mean was:


              He asked if this would be promoted to LRC:


              @Name(hitCount)
              public class HitCount{.. }


              No, cause the default scope for a javaBean is Event. If it had an @Stateful, it would be promoted cause it's an EJB now. I didn't say that javaBeans can't be included in a LRC, they can with the @Scope(ScopeType.CONVERSATION).


              :)

              • 4. Re: Doubt: Conversation?
                Arbi Sookazian Master

                Israel Fonseca wrote on Jul 29, 2009 18:28:


                No, cause the default scope for a javaBean is Event. If it had an @Stateful, it would be promoted cause it's an EJB now.


                This statement is not 100% accurate.  Not because it's an EJB now.  It's because it's a SFSB which has default scope of conversation.  It's b/c of the conversation scope that would allow the LRC promotion to occur.  The default scope of a SLSB is stateless, and the LRC would not happen.


                I tested a couple scenarios out of curiosity.  In the first case below (conversation scope), the LRC begins after startup() method completes successfully.  In the 2nd case, the LRC does not begin and the destroy() method is executed b/c there is a temporary conversation only.  The interesting thing is that Seam ignores the @Begin annotation in the 2nd case and does not seem to throw any exception or message (unless it's logged at a lower level than INFO).


                @Name("startConversation")
                @AutoCreate
                @Scope(ScopeType.CONVERSATION)
                public class TestStartConversation {
                     
                     @Logger Log log;
                     
                     @Begin(join=true)
                     public void startup(){
                          log.info("in start()");
                     }
                     
                     @Destroy
                     public void destroy(){
                          log.info("in destroy()");
                     }
                     
                     
                }



                @Name("startConversation")
                @AutoCreate
                @Scope(ScopeType.EVENT)  //default scope
                public class TestStartConversation {
                     
                     @Logger Log log;
                     
                     @Begin(join=true)
                     public void startup(){
                          log.info("in start()");
                     }
                     
                     @Destroy
                     public void destroy(){
                          log.info("in destroy()");
                     }
                     
                     
                }



                The LRC begins with this version as well (session scope):


                @Name("startConversation")
                @AutoCreate
                @Scope(ScopeType.SESSION)
                public class TestStartConversation {
                     
                     @Logger Log log;
                     
                     @Begin(join=true)
                     public void startup(){
                          log.info("in start()");
                     }
                     
                     @Destroy
                     public void destroy(){
                          log.info("in destroy()");
                     }
                     
                     
                }

                • 5. Re: Doubt: Conversation?
                  Israel Fonseca Apprentice

                  lol, maybe my English is a little rust and that's why i didn't put the right meaning in the sentence. But anyway, what you say, is what i want to mean in the end.


                  But the second example do not start a LRC? This is strange enough to be a bug.

                  • 6. Re: Doubt: Conversation?
                    Arbi Sookazian Master

                    I don't use a lot of event-scoped components, so haven't seen that before.  Try it yourself.

                    • 7. Re: Doubt: Conversation?
                      Prathamesh Gaddam Novice
                      Thank you, Israel and Arbi ! I tried to rate ur replies however it throw error 'object not found: jsquery'.

                      1. I'm unable to get 'temporary conversation'. Is it the default scope of the bean or else?

                      2. The conversation rules in seam reference are confusing me. It say conversation can be demoted/promoted then how to restart/close&start it?

                      The scenerio:
                      1. View loaded on menu click
                      2. Search operation
                      3. Clicked same menu-option for view

                      Problem: The search parameter in url are not removed. Only cid is changed.

                      Code:
                      @Name("menu")
                      @Scope(ScopeType.SESSION)
                      public class MenuBean {

                           public void endConversationAndRedirect(final String viewId){
                                log.debug("endConversationAndRedirect: clicked on " + viewId);
                              Manager.instance().endRootConversation(true);

                              Redirect redirect = Redirect.instance();
                              redirect.setViewId(viewId);
                              redirect.execute();
                           }
                      }

                           
                      NewMenu.xhtml               <rich:menuItem id="IssuesList" value="Issues List"
                                                         action="#{menu.endConversationAndRedirect('/IssuesList.xhtml')}">
                                                    </rich:menuItem>

                      Thank you in advance!
                      • 8. Re: Doubt: Conversation?
                        Israel Fonseca Apprentice

                        try to make your action point to a method like this:




                        @End(beforeRedirect="true")
                        public String redirect(String uri){
                        return uri;
                        }
                        





                        See if it solves your problem.

                        • 9. Re: Doubt: Conversation?
                          Prathamesh Gaddam Novice

                          Thank you Israel, for speedy response!


                          The code 'Manager.instance().endRootConversation(true)' does the same (fingers crossed) w.r.t the details I have read. The 'true' in endRootConversation(),  ends the conversation and any of its nested conversation before re-direct.


                          However, the problem is same. Unable to clear the pageparam in url on re-selection of the menuItem, why?

                          • 10. Re: Doubt: Conversation?
                            Israel Fonseca Apprentice

                            I got some problems like that in the past too (restarting conversation)... I can't help you precisely cause i never used page-params anyway, but let's see... does the bean state get cleaned? Is the only problem the url page params?

                            • 11. Re: Doubt: Conversation?
                              Prathamesh Gaddam Novice
                              I was enjoying week-end. Sorry, I was unable to reply!

                              Here are the step I follow:
                              Step1: Successful Login goes to home page
                              http://localhost:8080/Portal/home.seam?cid=23

                              Step2: Menu click
                              http://localhost:8080/Portal/IssuesList.seam?order=id+desc&cid=24

                              Step3: Search
                              http://localhost:8080/Portal/IssuesList.seam?order=id+desc&status=Open&priority=Blocker&issueId=&issueTopic=&cid=24

                              Step4: Menu click [conversation ends, URL has pageparam and no cid. However debug page shows new cid]
                              http://localhost:8080/Portal/IssuesList.seam?order=id+desc&status=Open&priority=Blocker&issueId=&issueTopic=

                              Problems/Query:
                              1. Null/empty valued param are added to URL
                              2. URL is not cleared
                              3. I guess on new conversation the values from components (bean state) in it, are cleared. Is is right?

                              Thank you for your patience,Israel!