3 Replies Latest reply on Apr 9, 2011 6:02 PM by lvdberg

    one EntityHome with different entity instances

    vata2999

      Hi,


      i have one entityHome, one form with many instance of entities so i have to create differenet instance of entity in EntityHome unless it will be override the last entity value bind to form



      users want to enter more than one record per entity and page


      assume : entityModel, entityModelHome , entityForm


      entityForm



      <h:inputText value="#{entityModelHome.instance.name}" />
      <h:inputText value="#{entityModelHome.instance2.name}" />
      <h:inputText value="#{entityModelHome.instance3.name}" />
      <h:commandButton value="save all " />
      




      How can i do that ?


      I create newInstance of entity each time user clicks button and try to  bind it to form via code
      but it doesn't work


      page.xhtml



      <h:inputText value="#{entityModelHome.instance2.name}" /> // this generate dynamically 
      <h:commandButton value="create another textinput" action="#{entityModelHome.myNewInstance}" />



      EntityModelHome.java




      @Name("entityModelHome")
      public class EntityModelHome extends EntityHome<EbImg> {
      
      
        public String myNewInstance(){
           EntityModelHome imhome =
      (EntityModelHome )  Component.getInstance(EntityModelHome.class, true);
                
      ValueExpression<entityModel> mynewinstance =  
       Expressions.instance().createValueExpression("#{entityModelHome.instance2}", 
      entityModel.class);
      
      imhome.setNewInstance(mynewinstance);
      
      
       imhome.getInstance(); //after submit form , assume to return #{entityModelHome.instance2.name} value of form but return null
          return null;
      }
      
      }








        • 1. Re: one EntityHome with different entity instances
          lvdberg

          Hi,


          maybe the Role annotation can do that for you, it isn't the same as multiple instances, but it is multiple Home's with the same bean.


          Leo

          • 2. Re: one EntityHome with different entity instances
            vata2999

            Hi Leo,


            Thanks for your reply


            sounds you are live Seam in Action



            I think it couldn't be possible to have one home and many instances though @Roles meet my need but the problem is i don't know how many instance i should create it depends on client and is dynamic so i have to create component dynamically do  u know how can i create Seam Components dynamically in entityHome and bind them to form ?

            • 3. Re: one EntityHome with different entity instances
              lvdberg

              Hi,


              If that is your problem, why don't you make a ManagerBean, which contains a Map or List of entities which are created on-the-fly. The EntityHome is a very nice component, but it has some restrictions which makes it often necessary to build your own component.


              You can learn a lot from the sources, they are included in the distribution and they provide a lot of info, to build specific components yourself.


              Leo