3 Replies Latest reply on Apr 9, 2011 6:02 PM by Leo van den berg

    one EntityHome with different entity instances

    omid pourhadi Apprentice

      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;
      }
      
      }