1 2 Previous Next 19 Replies Latest reply on Apr 20, 2007 7:48 AM by rbalaga

    New Conversation issue

      I have a stateful session bean called SiteEditor (Conversation scoped) with a create method. I wish to from a page backed by this bean, to open up another page with a SiteEditor bean as its backing bean (new data).

      When trying to do this I can open the first siteEditor page, but when I use the link to open up the new siteEditor page (it refreshes but shows the old data).

      The two relevant functions in the siteEditor bean are :

      @Create
      @Begin(join=true)
       public void createSiteEditor(){
      
       log.info("Creating");
      
       if (utilityID.getId() == 0){
       site = new Site();
       isNew = true;
       } else {
       site = (Site) em.find(Site.class, utilityID.getId());
       if (site==null){
       // TODO throw error, no site found for the id.
       } else {
       siteChildren = site.getChildren();
       isNew = false;
       }
       }
       }
      


      and

      @End
       public String editContract(){
       if (utilityID==null) utilityID = new UtilityId();
       utilityID.setId(selectedChild.getId());
      
       if (selectedChild instanceof Site)
       return "showsite";
       else if (selectedChild instanceof Plot)
       return "editplot";
       else if (selectedChild instanceof Region)
       return "editregion";
       else if (selectedChild instanceof Block)
       return "editblock";
       else if (selectedChild instanceof Phase)
       return "editphase";
       else
       return "error";
       }
      


      I also put a log messge in the @Destroyed method and I see this occur in the expected pattern.
      The one issue that causes my problem is that when I press on the button the first time the create function is not called, its as if the page is reusing the siteEditor left over from the previous conversation (even though I called the @End method).

      One extra piece of information is that if I then repress on the same commandButton a second time a new siteEditor is created.

      The xhtml code is as follows:

      <ui:define name="body">
       <h1>Site Editor</h1>
       <h:form>
       <table>
       <tr>
       <td><h:outputText value="Name" /></td>
       <td><h:inputText value="#{siteEditor.site.name}" /></td>
       <td></td>
       <td rowspan="8" vAlign="top">
      
       <c:if test="#{siteEditor.new}" >
       <table>
       <tr><td>
       <h:commandButton action="#{siteEditor.create}" value="Create" rendered="#{siteEditor.new}"
       class="formButton" style="width: 166px;"/>
       </td></tr>
       <tr><td>
       <h:commandButton action="#{siteEditor.done}" value="Cancel"
       class="formButton" style="width: 166px;" immediate="true"/>
       </td></tr>
       </table>
       </c:if>
       <c:if test="#{!siteEditor.new}">
       <table>
       <tr><td>
       <h:commandButton action="#{siteEditor.update}" value="Update"
       class="formButton" style="width: 166px;"/>
       </td></tr>
       <tr><td>
       <h:commandButton action="#{siteEditor.delete}" value="Delete"
       class="formButton" style="width: 166px;" immediate="true"/>
       </td></tr>
       <tr><td>
       <h:commandButton action="#{siteEditor.done}" value="Finish"
       class="formButton" style="width: 166px;" immediate="true"/>
       </td></tr>
       </table>
       </c:if>
       </td>
       </tr>
       <tr>
       <td><h:outputText value="Parent" /></td>
       <td>
       <h:selectOneMenu value="#{siteEditor.site.parent}" converter="ContractConverter" >
       <f:selectItems value="#{selectItems.contractList}" />
       </h:selectOneMenu>
       </td>
       </tr>
       <tr>
       <td><h:outputText value="ID" /></td>
       <td><h:inputText value="#{siteEditor.site.accountsID}" /></td>
       </tr>
       <tr>
       <td><h:outputText value="Area" /></td>
       <td><h:inputText value="#{siteEditor.site.area}" /></td>
       </tr>
       <tr>
       <td><h:outputText value="Address" /></td>
       <td><h:inputText value="#{siteEditor.site.address.housename}" /></td>
       </tr>
       <tr>
       <td></td>
       <td><h:inputText value="#{siteEditor.site.address.streetname}" /></td>
       </tr>
       <tr>
       <td></td>
       <td><h:inputText value="#{siteEditor.site.address.town}" /></td>
       </tr>
       <tr>
       <td></td>
       <td><h:inputText value="#{siteEditor.site.address.city}" /></td>
       </tr>
       <tr>
       <td></td>
       <td><h:inputText value="#{siteEditor.site.address.county}" /></td>
       </tr>
       <tr>
       <td></td>
       <td><h:inputText value="#{siteEditor.site.address.postcode}" /></td>
       </tr>
       <tr>
       <td><h:outputText value="Price" /></td>
       <td><h:inputText value="#{siteEditor.site.price}" /></td>
       </tr>
       <tr>
       <td><h:outputText value="Sub Contracts" /></td>
       <td></td>
       </tr>
       <tr>
       <td colspan="2">
       <h:dataTable value="#{siteChildren}" var="c" rendered="#{siteChildren.rowCount>0}">
       <h:column>
       <f:facet name="header">ID</f:facet>
       <h:outputText value="#{c.accountsID}" />
       </h:column>
       <h:column>
       <f:facet name="header">Name</f:facet>
       <h:outputText value="#{c.name}" />
       </h:column>
       <h:column>
       <f:facet name="header">Action</f:facet>
       <h:commandButton action="#{siteEditor.editContract}" value="View" />
       </h:column>
       </h:dataTable>
       </td>
       </tr>
       </table>
       <h:messages showDetail="true" />
      
       </h:form>
      
      
       </ui:define>
      


      If anybody has any ideas I would be very greatful.

      Many thanks,

      James

        • 1. Re: New Conversation issue
          gavin.king

          Conversations begin and end at *request boundaries*, NOT when the @End or @Begin method is called. (There are really, really good reasons why it is done this way.)

          So, basically, in this case, the @Begin method has the effect of cancelling out the @End.

          It is better to use a PAGE scope component in this case.

          • 2. Re: New Conversation issue
            rizviatt

            Would you explain what you mean by "Request boundaries". What if define a @Begin but not a @End. Then when will conversation end?

            • 3. Re: New Conversation issue
              gavin.king

              Request boundaries means the beginning and end of the HTTP request cycle.

              ie. You cannot end a conversation and begin a new one in one request. This always requires two requests.

              • 4. Re: New Conversation issue
                rizviatt

                Thanks for the reply.Pardon me but i failed to understand if Conversation contexts begin and end at request boundaries. Then what is the difference between a Conversation scope and Request scope(or Event scope).

                Once Again Thanks For the reply.

                • 5. Re: New Conversation issue
                  gavin.king

                  The difference is that the event scope always begins and ends in the *same* request.

                  • 6. Re: New Conversation issue
                    rizviatt

                    Q1)So in a Conversation context the conversation is alive over a number of Http requests?

                    Q2)SO for a Stateful Session bean with a method with @Begin annotation. When will the Conversatione end?

                    Thanks again for the reply

                    • 7. Re: New Conversation issue
                      gavin.king

                      1) Yes, that's the whole point.
                      2) When you hit an @End method.

                      • 8. Re: New Conversation issue
                        gavin.king

                        P.S. It sounds like you were really looking for the PAGE context in your original problem.

                        • 9. Re: New Conversation issue
                          gavin.king

                           

                          "gavin.king@jboss.com" wrote:
                          1) Yes, that's the whole point.
                          2) When you hit an @End method.


                          I should say: it ends at the end of the request in which the @End method was called.


                          Or it can be ended by <end-conversation/> in a jPDL pageflow definition.

                          • 10. Re: New Conversation issue
                            rizviatt

                            Ref-1) Okay Now it has cleared my doubts. Actually I was confused with your previous Reply

                            "Conversations begin and end at *request boundaries*, NOT when the @End or @Begin method is called. (There are really, really good reasons why it is done this way.)

                            So, basically, in this case, the @Begin method has the effect of cancelling out the @End.

                            It is better to use a PAGE scope component in this case."

                            But Now its clarified. Thanks

                            Ref-2) So what if in Stateful Session Bean there is a Method with @Begin Annotation but there is no method with @End annotation. When will the conversation end?.

                            Thanks For The Replies

                            • 11. Re: New Conversation issue
                              gavin.king

                              It will end when the conversation times out.

                              Or, if you are doing workspace management, when the user clicks the destroy workspace button. (See the issues demo.)

                              • 12. Re: New Conversation issue
                                rizviatt

                                Which Demo example are you talking about?

                                • 13. Re: New Conversation issue
                                  rbalaga

                                  I have one question about difference between Event scoped componets and Conversation scoped componets.

                                  I know that Conversation componets can span a few requests etc.

                                  But what is difference between Event and Conversation if the Conversation componet is not promoted to long running conversation?

                                  • 14. Re: New Conversation issue
                                    pmuir

                                    AFAIK, none

                                    1 2 Previous Next