6 Replies Latest reply on Oct 28, 2010 6:43 PM by kragoth

    save parent & child simoltaneously

    vata2999

      Hi,
      I got stuck in situation that need save parent/child simoltaneously but
      i come up with nothing can you suggest me an idea ?
      PS : my main problem is when i have more than one child
      thanks in advanced

        • 1. Re: save parent & child simoltaneously
          vata2999

          Maybe it's better to change my question
          How can I inject same context variable twice in actionBean ?



          @Name("relevent")
          @Entity
          class Relevent
          



          actionBean.java



          @In
          Relevent relevent;
          @In
          Relevent relevent2; //unknown context variable name
          


          form.xhtml




          h:inputText value{relevent.name} 
          h:inputText value{relevent2.name}  // this cause the problem









          • 2. Re: save parent & child simoltaneously
            kragoth

            You cannot inject multiple instances of a component.


            Instead of trying to inject 2 children, inject the parent and then reference the collection containing the children.


            Then as long as you have a cascading relationship merging the parent will save both children. If it is not a cascading relationship then manually call persist on each child. (Assuming flush mode is manual).

            • 3. Re: save parent & child simoltaneously
              vata2999

              Thanks tim for your advice You cannot inject multiple instances of a component
              as i know seam-gen using java reflection to create instance of entity and bind it to a from
              with entity.instance.property so i tried to make a new instance of my relevent class in actionbean as below




              @Transactional
              public Relevent getRelevent2(){
              return Relevent.class.newInstance();
              }
              


              that works perfectly but after i bind it to a form like



              h:inputText value=actionBeanName.relevent2.property


              and submit form  all property returns null
              any other idea ?




              • 4. Re: save parent & child simoltaneously
                lvdberg

                Hi,


                why don't you use the seam container to do this for you ? So something like:


                <component      auto-create="true" 
                          class="yourpackage.Relevent"
                          name="relevent1" />
                
                <component      auto-create="true" 
                          class="yourpackage.Relevent"
                          name="relevent2" />
                
                
                



                Leo

                • 5. Re: save parent & child simoltaneously
                  vata2999

                  That was as a piece of cake! :-D you save my day
                  Thanks Leo

                  • 6. Re: save parent & child simoltaneously
                    kragoth

                    Leo van den Berg wrote on Oct 28, 2010 06:43:


                    Hi,

                    why don't you use the seam container to do this for you ? So something like:

                    <component      auto-create="true" 
                              class="yourpackage.Relevent"
                              name="relevent1" />
                    
                    <component      auto-create="true" 
                              class="yourpackage.Relevent"
                              name="relevent2" />
                    
                    
                    



                    Leo



                    I did not know that trick! Nice one Leo. :)