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

    Add/Edit Page

    mrwhite

      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
          pmuir

          Yes.

          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
            mrwhite

            Lets take the blog example.

            I have my BlogService thats hast the following code:

             @RequestParameter("blogEntryId")
             private String blogEntryId;
            
             @In(required=false)
             @Valid
             private BlogEntry newBlogEntry;
            
             @Factory("newBlogEntry")
             public void createBlogEntry()
             {
             if(blogEntryId != null)
             {
             newBlogEntry = get Blog by ID ...
             }
             else newBlogEntry = new BlogEntry();
             }
            
             public String saveEntry()
             {
             em.persist(newBlogEntry);
             return "home";
             }
            


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



            • 3. Re: Add/Edit Page
              gavin.king

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

              • 4. Re: Add/Edit Page
                bfo81

                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 ;).