4 Replies Latest reply on Jul 20, 2006 5:14 AM by hdslkf hklsdg

    Add/Edit Page

    Peter Jerer Newbie

      Hi everyone,
      i want a page that creates a new object when no id for an object is provided or retriebes an object fromt the db when a id was passed by a request parameter.

      I want to have one form for editing and adding of blogentries and i dont want to build two forms, one for adding and another one for editing.

      And i want to provide these functions by one seam component.

      Is that possible?

        • 1. Re: Add/Edit Page
          Pete Muir Master


          It's very hard to give help for such a non-specific problem, but some ideas

          * Use facelets and templating to create a generic form which can be embedded
          * Think about where you whether you are going to use conversations, and if so, where you want them to start/end and when you want to enable/disable their propogation
          * Consider what the differences are between persisting a new object and updating an existing one

          • 2. Re: Add/Edit Page
            Peter Jerer Newbie

            Lets take the blog example.

            I have my BlogService thats hast the following code:

             private String blogEntryId;
             private BlogEntry newBlogEntry;
             public void createBlogEntry()
             if(blogEntryId != null)
             newBlogEntry = get Blog by ID ...
             else newBlogEntry = new BlogEntry();
             public String saveEntry()
             return "home";

            The action is always: action="#{blogService.saveEntry}"
            Is that the right way to solve this?

            • 3. Re: Add/Edit Page
              Gavin King Master

              You would have to use merge() instead of persist().

              • 4. Re: Add/Edit Page
                hdslkf hklsdg Apprentice

                Whow... I always thought one should use persist() for new entities and merge() for existing edited entities. Now I know that all you need is merge(). Thanks Gavin ;).