5 Replies Latest reply on Jan 4, 2009 4:55 AM by Ingo Jobling

    Newbie question, how to create new item

    philip andrew Newbie

      Hi,


      I used seamgen to create my project from the database.


      Now I have lots of pages which can show my DB contents.


      I want to create a link (not button) on one of my pages which will allow user to create a new item.
      First, I tried to make the link direct the user to ArtGroupEdit.xhtml, but this hows the previously edited item.
      I want to see a new empty item for the user to fill in.


      Thanks, Philip

        • 1. Re: Newbie question, how to create new item
          Daniel Hinojosa Master

          If I understand your question right, what typically is done, is you map two different entity components.  One that is to be a new entity (used for creation) and a managed entity (used to update, and delete).  Take a look at the framework section of the documentation for an example.

          • 2. Re: Newbie question, how to create new item
            Ingo Jobling Master

            Since you used SeamGen, you have an EntityHome to manage the instance.  The getInstance method will, if the id has been set, query the database and return a managed instance.  If the id has not been set, a new instance, which can subsquently be persisted, will be returned.  The isManaged method can be used to distinguish these cases.


            Getting back to your original question, the edit page will cover both of these cases, calling update if the instance is managed, and persist if if is not.


            It would seem that in your case you are passing the id of an existing instance, so you are in update mode.  If you ensure that no id is passed in your link, you should go into the mode you desire, allowing you to create a new instance.

            • 3. Re: Newbie question, how to create new item
              Ingo Jobling Master

              Referring to the code produced by SeamGen, look at ArtGroupEdit.page.xml, as well as the rendered attribute of the buttons on the ArtGroupEdit.xhtml page.

              • 4. Re: Newbie question, how to create new item
                philip andrew Newbie
                Hi,

                I tried to clear the seam component.

                  @Begin(join=true)
                  public String itemSelectedNew(String name, String actionResult, String seamComponent) {
                    // Clear seam component
                    EntityHome e1 = (EntityHome) Component.getInstance(seamComponent, true);
                    e1.clearInstance();
                    // Return page to go to
                    return this.itemSelected(name, actionResult);
                  }

                Is this right?
                Not seem to work in one case and work in another case...

                Philip

                • 5. Re: Newbie question, how to create new item
                  Ingo Jobling Master

                  Set the id to null, subsequent call to getInstance will return a new instance.


                  If your entity is Foo, it would be



                  e1.setFooId(null);
                  e1.wire();
                  



                  Assuming that your EntityHome was produced by SeamGen.