2 Replies Latest reply on Feb 19, 2009 1:13 PM by Marcio Endo

    DataModelSelection and multiple collections

    Fernando Gonzalez Newbie

      I know this topic has been beaten to death, but I've (unsuccessfully) tried  all the of the solutions proposed in previous topics...


      My problem is the following:


      I have Entity A, which has a Collection of Objects type B.
      B then has a Collection of Objects type C.


      since B is not really tabular data, I use ui:repeat to lay it out the way its meant to be.


      This is the create entity A form:


      <h:form>
      Name: <h:inputText value="#{A.name}"/><br/>
      Description: <h:inputText value="#{A.description}"/><br/>
                              <h:commandLink value="Add B Object" action="#{customerSegmentManager.addB}"/>                     
                              <ui:repeat value="#{mb}" var="_b">                
                                              <h:dataTable value="#{_b.cList}" var="_c">
                                                      <h:column>
                                                              <h:outputText value="#{c.name}"/>
                                                      </h:column>
                                                      <h:column>
                                                              <h:outputText value="#{c.value}"/>
                                                      </h:column>
                                              </h:dataTable>            
                                              <h:commandLink action="#{aManager.addC}" value="Add C" immediate="true"/>
                              </ui:repeat>                              
                              <h:commandButton value="Save" action="#{aManager.save}" />
                      </h:form>



      The workflow is the following:
      You create a new A Entity, and you add a couple of B Entities to it. (They are displayed in the ui:repeat control).
      You then click the add C link to go to a form that creates a new C Entity and adds it to the selected B Entity


      aManager is decribed here:


      @Name("aManager")
      @Scope(ScopeType.CONVERSATION)
      public class AManager {
              
              @In(create=true) @Out
              AEntity A;
              
              @DataModel
              List<Subsegment> mb;
              
              
              @DataModelSelection("mb")
              @Out(required=false)
              BEntity B;
              
              @In(create=true) @Out
              CEntity C;
              
              @In
              EntityManager entityManager;
      
              @End
              public String save()
              {
                      entityManager.persist(A);
                      return "";
              }
              
                      
              public String addC()
              {               
                      return "/addC.xhtml";
              }
      
      
              public String saveC()
              {
                      C.setSubsegment(subs);
                      B.getCList().add(C);            
                      return "/createA.xhtml";
              }
      
              public String addB()
              {
                      if(A.getBList()==null)
                      {
                              ArrayList<BEntity> list = new ArrayList<BEntity>();
                              A.setBList(list);
                      }
                      BEntity s = new BEntity();              
                      A.getBList().add(s);
                      s.setA(A);
                      mb = A.getBList();
                      return "";
              }
              
              @Begin(join=true)
              public String createA()
              {
                      return "/createA.xhtml";
              }
              
              
              @Factory("mb")
              public void getBList()
              {
                      mb = ( A.getBList()==null ) ?  new ArrayList<BList>() : A.getBList();
              }
              
              
      }
      


      When ever I click the addC link, it correctly takes me to addC.xhtml, which just has a simple form:


                      <h:form>
                              Variable: <h:selectOneMenu  value="#{C.variable}">
                                              <s:selectItems value="#{variables}" var="v" label="#{v.name}" />
                                              <s:convertEntity/>
                                       </h:selectOneMenu> 
                              Association: <h:selectOneMenu value="#{C.association}">
                                              
                                          </h:selectOneMenu>
                              Filter: <h:inputText value="#{C.value}"/>
                              Value: <h:commandButton value="Save" action="#{AManager.saveC}" />
                      </h:form>




      When I click the Save link on addC, and saveC gets called on AManager, I get a null pointer exception. I don't have any ideas, I have already started a long running conversation (as soon as createA is called), the datamodel is correctly scoped (AFAIK), and @DataModelSelection is being correctly used...


      If anyone has any ideas I'd greatly appreciate it...