14 Replies Latest reply on Aug 6, 2007 10:18 AM by pmuir

    begin-conversation in Seam2 prevents data load

    damianharvey

      Morning,

      I have an issue with jboss-seam-2.0.0.BETA1.

      I have an all-on-one CRUD page where selecting an item in the table reloads the current page and populates the create/edit form in another div. If the page.xml has <begin-conversation join="true"/> then the form will not be populated (ie. the form field values are not set). If I remove the <begin..>, then it works (the form field values are populated with the data from the selected table row).

      A conversation isn't required for my example page, however I have some more complex pages where one is.

      The same behaviour was not present in Seam 1.2.1GA. I have tried this with a sample app Seam-Gen'd using both Seam2.0.0 and also with Seam1.2.1.

      My example form PersonList.xhtml:

      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       xmlns:s="http://jboss.com/products/seam/taglib"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:a="https://ajax4jsf.dev.java.net/ajax"
       xmlns:rich="http://richfaces.ajax4jsf.org/rich"
       template="layout/template.xhtml">
      
      <ui:define name="body">
       <h:form id="person" styleClass="edit">
       <rich:panel>
       <f:facet name="header">Edit Person</f:facet>
      
       <s:decorate id="personidDecoration" template="layout/edit.xhtml">
       <ui:define name="label">personid</ui:define>
       <h:inputText id="personid"
       required="true"
       disabled="#{personHome.managed}"
       value="#{personHome.instance.personid}">
       <a:support event="onblur" reRender="personidDecoration" bypassUpdates="true"/>
       </h:inputText>
       </s:decorate>
      
       <s:decorate id="firstnameDecoration" template="layout/edit.xhtml">
       <ui:define name="label">firstname</ui:define>
       <h:inputText id="firstname"
       required="true"
       size="50"
       maxlength="50"
       value="#{personHome.instance.firstname}">
       <a:support event="onblur" reRender="firstnameDecoration" bypassUpdates="true"/>
       </h:inputText>
       </s:decorate>
      
       <s:decorate id="lastnameDecoration" template="layout/edit.xhtml">
       <ui:define name="label">lastname</ui:define>
       <h:inputText id="lastname"
       required="true"
       size="50"
       maxlength="50"
       value="#{personHome.instance.lastname}">
       <a:support event="onblur" reRender="lastnameDecoration" bypassUpdates="true"/>
       </h:inputText>
       </s:decorate>
      
       <div style="clear:both">
       <span class="required">*</span>
       required fields
       </div>
      
       </rich:panel>
       </h:form>
      
       <rich:panel>
       <f:facet name="header">Person search results</f:facet>
       <div class="results" id="personList">
       <rich:dataTable id="personList"
       var="person"
       value="#{personList.resultList}"
       rendered="#{not empty personList.resultList}">
       <h:column>
       <f:facet name="header">
       personId
       </f:facet>
       #{person.personid}
       </h:column>
       <h:column>
       <f:facet name="header">
       firstName
       </f:facet>
       #{person.firstname}
       </h:column>
       <h:column>
       <f:facet name="header">
       lastName
       </f:facet>
       #{person.lastname}
       </h:column>
       <h:column>
       <f:facet name="header">action</f:facet>
       <s:link view="/PersonList.xhtml"
       value="Select"
       id="person">
       <f:param name="personPersonid"
       value="#{person.personid}"/>
       </s:link>
       </h:column>
       </rich:dataTable>
      
       </div>
       </rich:panel>
      
      </ui:define>
      
      </ui:composition>
      


      My PersonList.page.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <page xmlns="http://jboss.com/products/seam/pages"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.0.xsd">
      
       <begin-conversation join="true"/> <!-- the line that causes my hair-loss -->
       <param name="personPersonid" value="#{personHome.personPersonid}"/>
      
      </page>
      


      Has the way that conversations are treated changed between 1.2.1 and 2.0.0? Nothing in the changelog.txt rings any bells. I have looked at the debug output but can't spot anything that would cause this behaviour.

      I can upload this sample app (both versions) if anyone would like to see it.

      Thanks,

      Damian.

        • 1. Re: begin-conversation in Seam2 prevents data load
          damianharvey

          ping?

          This is preventing me from upgrading to Seam2.0.0 so any help would be appreciated.

          • 2. Re: begin-conversation in Seam2 prevents data load
            gavin.king

            I recommend you put the Seam src in your sourcepath and debug to find the cause of the problem/difference.

            Your description doesn't really help find the cause.

            • 3. Re: begin-conversation in Seam2 prevents data load
              damianharvey

              I've tried to debug it, but haven't been able to find a solution.

              #1 : Successful Call
              On a page that successfully loads without <begin-conversation join="true"/> specified in the page.xml, the following methods get hit in this order:
              - setId()
              - setInstance()
              - setDirty()
              - find()
              - getInstance()
              - initInstance()
              - find()
              - setInstance()

              #2 : Unsuccessful Call
              On a page that does not load successfully (ie with begin-conversation) the following methods get hit in this order:
              - setId()
              - setInstance()
              - setDirty()
              - find()
              - getInstance()

              The first setInstance() will not do anything as the object hasn't been loaded from the database yet. The initInstance() is the critical piece missing from the unsuccessful call. This is called from getInstance() if instance is null. The big difference between the two is that instance is not null at setId() in #2.

              I thought that this is because instance is a property of an object (Home) that is conversationally scoped and I have opted to join this conversation. However I tried setting instance to null in my overriden find(). Instance was repopulated somewhere else between the find() and the getInstance().

              I can't see a way around this at present, so would very much appreciate any help.

              Thanks,

              Damian.

              • 4. Re: begin-conversation in Seam2 prevents data load
                pmuir

                Post personHome.

                • 5. Re: begin-conversation in Seam2 prevents data load
                  damianharvey

                  Thanks Pete. Any help is very much appreciated on this. Here is the PersonHome. It is unchanged from what was created by Seam Gen:

                  package com.locuslive.odyssey.entity;
                  
                  import org.jboss.seam.annotations.Name;
                  import org.jboss.seam.framework.EntityHome;
                  
                  @Name("personHome")
                  public class PersonHome extends EntityHome<Person> {
                  
                   public void setPersonPersonid(Byte id) {
                   setId(id);
                   }
                  
                   public Byte getPersonPersonid() {
                   return (Byte) getId();
                   }
                  
                   @Override
                   protected Person createInstance() {
                   Person person = new Person();
                   return person;
                   }
                  
                   public void wire() {
                   }
                  
                   public boolean isWired() {
                   return true;
                   }
                  
                   public Person getDefinedInstance() {
                   return isIdDefined() ? getInstance() : null;
                   }
                  
                  }
                  


                  Thanks,

                  Damian.

                  • 6. Re: begin-conversation in Seam2 prevents data load
                    pmuir

                    Take a look at the ui example, it does almost exactly this to load the selectItems.xhtml page and compare where it differs (as this page works correctly). (Specifically I'm worried something may be broken in your custom methods above, you should try without your custom id setters, using a converter).

                    • 7. Re: begin-conversation in Seam2 prevents data load
                      damianharvey

                      Cheers Pete. I'll try that. However I'm doing very little custom anything. Those methods are generated by Seam gen. This is just a Seam Gen'd project where I'm wedging the insert/edit to be on the same page as the table list.

                      It works fine in 1.3ALPHA (and all releases before that).

                      Damian.

                      • 8. Re: begin-conversation in Seam2 prevents data load
                        damianharvey

                        Pete,

                        I have modified the UI example and it shows the same problem.

                        I added an ID to the personHome in components.xml:

                        <framework:entity-home name="personHome" entity-class="org.jboss.seam.example.ui.Person">
                         <framework:id>#{personId}</framework:id>
                        </framework:entity-home>

                        I changed selectItems.xhtml to include the following links at the top:
                        <h:form>
                         <s:link view="/selectItems.xhtml" action="#{personHome.find}" value="Load Pete">
                         <f:param name="personId" value="1"/>
                         </s:link>
                         <br/>
                         <s:link view="/selectItems.xhtml" action="#{personHome.find}" value="Load Damian">
                         <f:param name="personId" value="2"/>
                         </s:link>
                        
                         <s:decorate template="decorateField.xhtml">
                         <ui:define name="label">ID</ui:define>
                         #{person.id}
                         </s:decorate>
                        ......
                        

                        I then added an entry for me in the import.sql. The idea is that when one of these links is clicked on the relevant entry should be loaded. Not surprisingly it doesn't work. If I remove <begin-coversation join="true"> from the pages.xml then it does work.

                        Can I call it a bug yet?

                        Thanks,

                        Damian.



                        • 9. Re: begin-conversation in Seam2 prevents data load
                          pmuir

                          I'm afraid thats working correctly for me :( Did you make any changes to pages.xml? The best way to do this is to post a patch with the changes you've made, then I can easily replicate here.

                          • 10. Re: begin-conversation in Seam2 prevents data load
                            damianharvey

                            Pete,

                            I made no changes to the pages.xml aside from removing the <begin-conversation> to get it working. The only changes that I made are outlined above.

                            I'll put together the patch as you mentioned. I'll raise a JIRA and attach it to that.

                            Cheers,

                            Damian.

                            • 11. Re: begin-conversation in Seam2 prevents data load
                              damianharvey

                              Ah, it works if I use Seam from CVS. Should have tried that earlier I suppose, but I still can't see why it doesn't work against the downloaded Seam 2.0.0.BETA. Here is the patch:

                              ### Eclipse Workspace Patch 1.0
                              #P jboss-seam
                              Index: examples/ui/resources/import.sql
                              ===================================================================
                              RCS file: /cvsroot/jboss/jboss-seam/examples/ui/resources/import.sql,v
                              retrieving revision 1.6
                              diff -u -r1.6 import.sql
                              --- examples/ui/resources/import.sql 13 Jun 2007 23:49:05 -0000 1.6
                              +++ examples/ui/resources/import.sql 5 Aug 2007 22:15:35 -0000
                              @@ -1,4 +1,6 @@
                               insert into person (name, age, hobbies) values ('Peter Muir', 25, '/works on Seam/, *of course*');
                              +insert into person (name, age, hobbies) values ('Damian Harvey', 99, '/quite likes using Seam/, *of course*');
                              +
                               insert into continent(name) values('North America');
                               insert into continent(name) values('South America');
                               insert into continent(name) values('Australasia');
                              Index: examples/ui/resources/WEB-INF/components.xml
                              ===================================================================
                              RCS file: /cvsroot/jboss/jboss-seam/examples/ui/resources/WEB-INF/components.xml,v
                              retrieving revision 1.9
                              diff -u -r1.9 components.xml
                              --- examples/ui/resources/WEB-INF/components.xml 1 Aug 2007 11:49:57 -0000 1.9
                              +++ examples/ui/resources/WEB-INF/components.xml 5 Aug 2007 22:15:35 -0000
                              @@ -19,7 +19,9 @@
                              
                               <framework:entity-query name="continents" ejbql="select c from Continent c" />
                              
                              - <framework:entity-home name="personHome" entity-class="org.jboss.seam.example.ui.Person" />
                              + <framework:entity-home name="personHome" entity-class="org.jboss.seam.example.ui.Person">
                              + <framework:id>#{personId}</framework:id>
                              + </framework:entity-home>
                              
                               <framework:entity-query name="colours" ejbql="select c from Colour c" />
                              
                              Index: examples/ui/view/selectItems.xhtml
                              ===================================================================
                              RCS file: /cvsroot/jboss/jboss-seam/examples/ui/view/selectItems.xhtml,v
                              retrieving revision 1.20
                              diff -u -r1.20 selectItems.xhtml
                              --- examples/ui/view/selectItems.xhtml 29 Jun 2007 16:43:46 -0000 1.20
                              +++ examples/ui/view/selectItems.xhtml 5 Aug 2007 22:15:35 -0000
                              @@ -22,6 +22,19 @@
                               <p><s:link view="/continents.xhtml" value="Edit the continent/country relationship." /></p>
                              
                               <h:form>
                              + <s:link view="/selectItems.xhtml" action="#{personHome.find}" value="Load Pete">
                              + <f:param name="personId" value="1"/>
                              + </s:link>
                              + <br/>
                              + <s:link view="/selectItems.xhtml" action="#{personHome.find}" value="Load Damian">
                              + <f:param name="personId" value="2"/>
                              + </s:link>
                              +
                              + <s:decorate template="decorateField.xhtml">
                              + <ui:define name="label">ID</ui:define>
                              + #{person.id}
                              + </s:decorate>
                              +
                               <s:decorate template="decorateField.xhtml">
                               <ui:define name="label">Title</ui:define>
                               <h:selectOneMenu value="#{person.honorific}">
                              


                              Cheers,

                              Damian.

                              • 12. Re: begin-conversation in Seam2 prevents data load
                                pmuir

                                Ok, glad it works. I can't immediately identify the change, but we've fixed a lot since 2.0.0.BETA :)

                                • 13. Re: begin-conversation in Seam2 prevents data load
                                  damianharvey

                                  Pete,

                                  Am I safe in assuming that whatever change was made will be in 2.0.0.GA or was there a cut-off date for that release?

                                  Is there a nightly build that I can try pre-GA release?

                                  Cheers,

                                  Damian.

                                  • 14. Re: begin-conversation in Seam2 prevents data load
                                    pmuir

                                    Yes, to release we just take a CVS HEAD snapshot. Currently nightly builds aren't available, but you can of course get CVS and compile. It's pretty stable atm.