7 Replies Latest reply on Feb 22, 2007 9:05 PM by bulloncito

    EntityHome setId problem

    dustismo

      Hi,

      I am using EntityHome for a basic crud page. It works fine for creating but doesn't work when I try to update.

      Here is the EntityHome class

      @Name("groupHome")
      public class GroupHome extends EntityHome<UGroup> {
      
       @In (required=true)
       private User user;
      
       @Override
       public void setId(Object id) {
       System.out.println("Setting ID: " + id);
       super.setId(id);
       }
      
       @End
       @Override
       public String persist() {
       return super.persist();
       }
      
       @Begin
       protected UGroup createInstance() {
       UGroup g = new UGroup();
       g.setUser(user);
       return g;
       }
      }
      


      and the form is:

      <h:form>
       <h:outputLabel for="name">Group Name:</h:outputLabel>
       <s:decorate>
       <h:inputText id="name" value="#{groupHome.instance.name}" />
       <s:message />
       </s:decorate>
      
      
       <h:selectOneListbox value="#{groupHome.instance.ugrouptype}">
       <s:selectItems value="#{groupTypes.resultList}" var="ugrouptype"
       label="#{ugrouptype.name}" noSelectionLabel="Please Select..." />
       <ec:convertEntity />
       <h:message for="ugrouptype" />
       </h:selectOneListbox>
       <h:commandButton value="Create Group" action="#{groupHome.persist}"
       styleClass="button" rendered="#{!groupHome.managed}" />
      
       <h:commandButton value="Update Group" action="#{groupHome.persist}"
       styleClass="button" rendered="#{groupHome.managed}" />
      
       <h:commandButton value="Delete Group" action="#{groupHome.persist}"
       styleClass="button" rendered="#{groupHome.managed}" />
       <h:messages />
       </h:form>
      



      And the relevent section of pages.xml

      
       <page view-id="/clients/admin_group.xhtml">
       <param name="groupId" value="#{groupHome.id}" converter="IntegerConverter" />
       </page>
      


      note that if I leave out the converter it throws
      java.lang.IllegalArgumentException: Provided id of the wrong type. Expected: class java.lang.Integer, got class java.lang.String


      But either way the setId method of the EntityHome is never called. What am I doing wrong??

      thanks,
      Dustin

        • 1. Re: EntityHome setId problem
          dustismo

          I still haven't figured this problem out.. Can anybody help?

          thanks
          Dustin

          • 2. Re: EntityHome setId problem
            gavin.king

            What initializes the page parameter in the first place? ie. how do you pass the parameter into that page?

            • 3. Re: EntityHome setId problem
              bulloncito

              What do you mean by initializing the parameter in the first place ? isn't that what the page parameter does ?

              I'm a seam newbie having a similar problem, if I select an entity from a h:dataTable using

              <s:link id="editUser" action="#{userSearch.editUser(user)}" propagation="join" >Edit</s:link>

              then display the create/update form, it displays creation form, if I manually set in the url the " userId " parameter then it shows the update form, even if I leave page, and come back again using conversation begin, it still shows update page with old selected entity, until I hit update or delete, I also have
              <page>
               <restrict>#{identity.loggedIn}</restrict>
               <param name="userId" value="#{userHome.id}" converterId="javax.faces.Long" />
               <begin-conversation join="true" />
               <navigation from-action="#{userHome.persist}">
               <end-conversation />
               <redirect view-id="/registered.xhtml">
               <param name="userId" value="#{userHome.id}" />
               </redirect>
               </navigation>
               <navigation from-action="#{userHome.update}">
               <end-conversation />
               <redirect view-id="/registered.xhtml">
               <param name="userId" value="#{userHome.id}" converterId="javax.faces.Long" />
               </redirect>
               </navigation>
              </page>


              ... if I select one entity on the dataTable, and the form displays creation form, with already filled in fields of selected entity, and press create, it throws lots of exceptions of null values for not-null fields wich are not handled by seam, warning me not to have two phase listeners, wich I don't. We kind of need some further examples on documentation about using Home objects, that would be nice, they seem to rule, if they work of course.

              I'm guessing we have similar problems propagating id's to home objects, if page parameters in pages.xml does not do this, then where do we have to ?

              A Seam Newbie wandering for enlightenment.

              • 4. Re: EntityHome setId problem
                gavin.king

                Does editUser() call setId()?

                It needs to.

                • 5. Re: EntityHome setId problem
                  gavin.king

                  BTW, I recommend starting from examples/contactlist or seam generate-entities.

                  • 6. Re: EntityHome setId problem
                    dustismo

                    I am passing the id in as a get parameter.. i.e.

                    http://localhost:8080/webapp/clients/admin_group.seam?groupId=1

                    I have looked at the contactlist example, and it doesn't really help (I need to have an actual EntityHome class, and ./seam generate-entities hasn't worked for me since 1.1.1 (I posted about it awhile ago and never figured out the problem)..

                    Thanks for any help,
                    Dustin

                    • 7. Re: EntityHome setId problem
                      bulloncito

                      Thanks for the quick response, I'm using declarative approach:

                      <factory name="user"
                       value="#{userHome.instance}"/>
                      
                      <framework:entity-home name="userHome"
                       entity-class="bco.time.ejb3.User"
                       entity-manager="#{entityManager}" />


                      I actually prefered to use extension but that was not working, so I used the seampay homeobjects as example, I tried using seamgen to find any differences, but the best for me was extending hotel booking example. Where should I call setId() ? on userHome ? I'm lost again. Should I inject userHome to call setId on it ? I'll try using extension then.