8 Replies Latest reply on May 26, 2008 4:16 AM by Jorge Ruiz

    Recursion in EntityHomes

    Francisco Peredo Newbie

      Hi!
      I am trying to implement the CRUD page for an entity that will represent a tree:

      Category many to one Category
      Category one to many Category


      Any hints on how could it be implemented?


      I am thinking about using NestedConversations so that when CategoryHome calls CategoryHome
      it would actually be calling a CategoryHome in a nested Conversation


      What do you guys think about it?
      Is it a good begining?


      Another possibility could be adding a java.util.Stack to the CategoryHome and use it to keep
      track the previous definedInstances


      Any hints?


      Regards,

        • 1. Re: Recursion in EntityHomes
          Francisco Peredo Newbie

          Hi!
          I am trying to understand the seam-generated applications.
          I seems that they work like this:



          • The EntityList.xhtml page show all the instances of an entity, it allows to search a particular subset of the instaces of that entity, there is no conversation here.

          • You can click a particular entity and view/inspect it, doing this will redirecto you  the Entity.xhtml page, still no  conversation.

          • From Entity.xhtm you may edit the current entity instance or you may add child Entity instances.

          • If you choose to modify the entity you are redirected to EntityEdit.xhtml, now we have a long running conversation (why, if we were fine util now without a conversation we need one now?)

          • If you choose add a chid entity, you also start a long running conversation... but I fail to see the point in doing it...

          • If you choose add a chid entity, and the child entity is of the same type as the parent entity... then you will have problems, because... how can you differentiate between the EntityHome of the parent entity and the EntityHome of the child entity? They are, in fact, the exact same component!!! If I click to add the recursive child, I end up creating a relationship between the current entity instance and itself.



          Now... I tought I could solve this problem by using nested conversations... but there is no conversation until after I click to add the child entity, therefore a nested conversation is not only not useful, it is plain wrong, because we don't even have a top-level conversation.


          Is the EntityHome/Entity.xml/EntityEdit.xml pattern as implemented in seam-gen usable for recursive relationships? I am really starting to think that the answer is no, because the EntityEdit.xml seams to be designed to always be called by Entity to edit the current instance, and never to create a new instance of the same type connected to the previously viewed instance...


          Do I make any sense? Can anyone offer any hints at all?


          Thanks,
          Francisco



          • 2. Re: Recursion in EntityHomes
            Francisco Peredo Newbie

            Hi!


            The problem seems to be that, when adding the chid entity instance over the recursive relationship, the id of the parenty entity is automatically propagated it doesn't matter if the Add child button has the parameter or not, it is propagated because it is in EntityEdit.page.xml... mmmm....


            What if I delete that line... well then the normal non-recursive Edit button will stop working...


            It seems that the EditEntity.xhml can only be used in the context of modifying a new entity and not in the context of adding a recursive child... and the pageflow defined just doesn't seem to allow any other use...


            The problem here seems to be that I have 3 alternative page flows..:



            1. From List all instances to Edit a new instance

            2. From List all instances to View an instance to Edit that instance

            3. From List all instances to View an instance to Edit a new child of that instance that is of the same type as the parent instance



            IMO the problem is that 2 and 3 get mixed... I need to make the aplication forget that it was Viewing an Entity so that i can create a a new instance  (as in 1) but at the same time it has to remember to connect that instance to the parent instance...


            Any hints at all?


            Regards,


            Francisco


            • 3. Re: Recursion in EntityHomes
              Pete Muir Master

              Francisco Peredo wrote on Mar 14, 2008 02:22 AM:


              Is the EntityHome/Entity.xml/EntityEdit.xml pattern as implemented in seam-gen usable for recursive relationships? I am really starting to think that the answer is no, because the EntityEdit.xml seams to be designed to always be called by Entity to edit the current instance, and never to create a new instance of the same type connected to the previously viewed instance...


              Not ootb. I would use an EntityHome to manage to the top level entity, and then write some extra code to manage the recursion.

              • 4. Re: Recursion in EntityHomes
                Francisco Peredo Newbie

                Hi!


                The thing is I don't quite get how the org.jboss.seam.framework.EntityHome receives the primary key through the query string.


                The query string key looks like this: entityNamePrimaryKeyName but I do not see any:


                
                @RequestParameter
                Long entityNamePrimaryKeyName;
                
                



                declared in org.jboss.seam.framework.EntityHome (of course it would be impossible since EntityHome is generic base clase inside the seam jar)


                I have been trying to understand how this works to change it and add recursive behavior but I don't get it.. If I go up in the inheritance hierarchy I can see that code to handle primary keys is added at the org.jboss.seam.framework.Home, but I don't know how the private Object id gets the value from the entityNamePrimaryKeyName request parameter.


                It uses an interceptor of some kind?  how does it work? how can it know wich query string parameter is the one that contains the primary key?


                Thanks


                Regards,


                Francisco

                • 5. Re: Recursion in EntityHomes
                  Francisco Peredo Newbie

                  Hi!


                  The Entity Home of, for example Users, with a primary key with name IdUser will look like this:


                  public void setUserIdUser(Long id) {
                            setId(id);
                       }
                  
                       public Long getUserIdUser() {
                            return (Long) getId();
                       }
                  



                  How does seam know it has to call this method? (It doesn't have a @RequestParameter anywhere!


                  Regards,


                  Francisco

                  • 7. Re: Recursion in EntityHomes
                    Francisco Peredo Newbie

                    Thanks, yes,  you are right, the Page parameters, sorry for the silly question...


                    I got it to the point where it saves the recursive child and not a referece to itself, the problem now is that after saving the child, instead of going back to view the parent, it goes to view the recently added child...

                    • 8. Re: Recursion in EntityHomes
                      Jorge Ruiz Newbie

                      hi, can you tell me how did you get it working using Page parameters?
                      thanx