14 Replies Latest reply on Jan 21, 2008 5:39 AM by mail.micke

    Conversations doing my head in - help

    mail.micke

      Hi

      Just picked up the Seam framework again and I'm currently struggling to get conversations working.

      My setup:
      JSF Mojarra (latest)
      Seam 1.2.1
      RichFaces 3.1.2
      JBoss 4.0.3SP1
      Facelets 1.1.14 (I think)

      My problem is simple what ever I try I can't get the conversation promoted into a long running one. Or at least that is what I suspect is going on.

      I have an action method annotated with @Begin(join=true) , and I am trying these ways of calling it:

      <s:link value="SeamLinkSearch" action="#{cptySearch.search}"/>
      <s:button value="SeamButtonSearch" action="#{cptySearch.search}"/>
      <h:commandButton action="#{cptySearch.search}" value="search"/>
      <a4j:commandButton action="#{cptySearch.search}" value="ajax search" reRender="searchResult"/>
      


      At the top of the page I have a #{conversation.id} printout, so I can see that the Id gets incremented for each submit.

      The first two Seam components doesn't even invoke the action method, from restore view they jump immediately to render response.

      The last two buttons, executes the action but the conversation Id is incremented.

      I think I'm missing something simple here... be gentle.

      Many thanks,
      micke


        • 1. Re: Conversations doing my head in - help
          nickarls

          Tried your code in a JBoss Tools project? It is really straightforward and assures that you don't struggle with some library conflict somewhere.

          • 2. Re: Conversations doing my head in - help
            samdoyle

            JBoss Tools is nice. I wish there was integration with NetBeans in addition to Eclipse.

            • 3. Re: Conversations doing my head in - help
              mail.micke

              hi all

              Can someone see an error in the way I try and kick-off a long running conversation?

              • 4. Re: Conversations doing my head in - help

                 

                "mail.micke@gmail.com" wrote:
                The last two buttons, executes the action but the conversation Id is incremented.


                This is because each request initializes a temporary conversation if a long-running conversation is not resumed. This means that your first page request resulted in a temporary conversation with a specific cid. The next request also results in a temporary conversation with an incremented cid, then that temporary conversation is promoted to long-running. The long-running conversation gets the cid for the temporary conversation that was promoted.

                Hope that helps.

                • 5. Re: Conversations doing my head in - help
                  mail.micke

                  Hi Jacob

                  Not quite sure I understood.

                  For the last two buttons the cid is always incremented, which I thought meant that the temporary conversation was never promoted in to a long running one.

                  Is this how it is suppose to be?
                  1. First page render, cid=1
                  2. Post back to @Begin(join=true) action method. cid=1 gets promoted to long running.
                  3. Returns from postback, and renders the same page. cid=1

                  For me it doesn't work like above, at step 3 cid=2

                  Many thanks,
                  Mike

                  • 6. Re: Conversations doing my head in - help

                     

                    "mail.micke@gmail.com" wrote:
                    Is this how it is suppose to be?
                    1. First page render, cid=1


                    Yes. This first rendering starts a temporary conversation which is cid=1. Once the page is rendered that temporary conversation is destroyed.

                    "mail.micke@gmail.com" wrote:
                    2. Post back to @Begin(join=true) action method. cid=1 gets promoted to long running.


                    No, another temporary conversation is started with cid=2 on the post back. Every request has a temporary conversation unless a long-running conversation is being resumed. If you log the conversation id in your @Begin method you will see cid=2.

                    Hope that clears things up.

                    • 7. Re: Conversations doing my head in - help
                      mail.micke

                      Ok,
                      so if I press the submit button again, then the cid should still be 2 right?

                      • 8. Re: Conversations doing my head in - help

                        Yes, since the action is annotated with @Begin(join=true). If join=true was not there you would get an exception.

                        • 9. Re: Conversations doing my head in - help
                          mail.micke

                          Hi,
                          thanks for your patience :)

                          Here is where I have problems, the cid still gets incremented (and doing my head in). Or at least I think so, pretty sure I tested this. Will make sure again tomorrow at work.

                          I wonder what I've done wrong? And isn't it also a bit strange that the s:button/link don't call my action method?

                          I bet this is going to be one of those problems where I've done something silly.

                          Thanks again,
                          Mike

                          • 10. Re: Conversations doing my head in - help
                            kukeltje

                            the s:button/link does not call your action method if the form on the page contains validation errors. I've been struggling with this for over a day once. Maybe you have the same problem

                            • 11. Re: Conversations doing my head in - help
                              mail.micke

                              I'm having the problem I thought I had, second click on the command button calling an action with @Begin(join=true) gets a new conversation id.

                              And I was wrong about the action not getting invoked with the seam ui components, they just don't seem to go through the usual jsf lifecycle (don't get the printouts from my timer phase listener).

                              Here is some more code, can you guys see anything wrong?

                              @Name("dataSearch")
                              @Scope(ScopeType.CONVERSATION)
                              public class DataSearch {
                              
                               private String pattern;
                              
                               @In("#{DataService}")
                               private DataService dataService;
                              
                               boolean onlyColl = false;
                               boolean withPrivate= false;
                               List<Data> results;
                              
                              
                               @Begin(join=true)
                               public String search(){
                               System.out.println("Conversation id in action: " +Conversation.instance().getId());
                               if(results == null){
                               System.out.println("results is NULL");
                               results = dataService.getData(pattern, onlyColl, withPrivate);
                               }
                              
                               return null;
                               }
                              //cut
                              
                              


                              And here is the XHTML body content :
                              
                               #{conversation.id}
                              
                               <h:form>
                               Search pattern:
                               <h:inputText value="#{dataSearch.pattern}"/>
                               <s:link value="SeamLinkSearch" action="#{dataSearch.search}"/>
                               <s:button value="SeamButtonSearch" action="#{dataSearch.search}"/>
                               <h:commandButton action="#{dataSearch.search}" value="search"/>
                               <a4j:commandButton action="#{dataSearch.search}" value="ajax search" reRender="searchResult"/>
                               <a4j:status startText="Working..." stopText=""/>
                              
                              
                               <rich:dataTable
                               id="searchResult"
                               rendered="#{not empty dataSearch.results}"
                               value="#{dataSearch.results}"
                               var="row"
                               rows="10">
                               <f:facet name="header">
                               <rich:datascroller for="searchResult"/>
                               </f:facet>
                               <rich:column>
                               <f:facet name="header">
                               Code
                               </f:facet>
                               #{row.code}
                               </rich:column>
                               <rich:column>
                               <f:facet name="header">
                               Name
                               </f:facet>
                               #{row.name}
                               </rich:column>
                               </rich:dataTable>
                              
                               <rich:messages showDetail="true"/>
                               </h:form>
                              
                              


                              • 12. Re: Conversations doing my head in - help
                                mail.micke

                                Hi

                                I just noticed that adding

                                propagation="join"
                                


                                to the s:button, starts a conversation and I get a "Beginning Conversation" log message.

                                But when clicking the s:button I notice that the dataSearch.pattern property is not set on my backing bean.

                                Any ideas?

                                Cheers

                                • 13. Re: Conversations doing my head in - help
                                  pmuir

                                  s:button/s:link DO NOT SUBMIT THE FORM!

                                  • 14. Re: Conversations doing my head in - help
                                    mail.micke

                                    Just re-read the docs and noticed the bit which says that the seam button doesn't submit the form.

                                    Also discovered the s:conversationPropagation tag.

                                    It seems to work just fine when using it with a h:commandLink , but not with h:commandButton.

                                    Anyway, sorry for the rant.

                                    Should the @Begin annotation work for me?