1 Reply Latest reply on Apr 16, 2009 7:16 PM by Arbi Sookazian

    Factory method is not firing

    Arbi Sookazian Master

      Seam 2.0.2-FP


      SFSB:


      @DataModel
           private List<Object[]> populateParametersList = new ArrayList<Object[]>();



      @Factory("populateParametersList")
           public void populateParameters(){...}



      xhtml:


      <a4j:form id="editParamFormTest">     
                     <rich:dataTable value="#{populateParametersList}" var="param">               
                           
                                <rich:column>
                                    <f:facet name="header"><h:outputText value="row count"/></f:facet>     
                                    <h:outputText value="#{populateParametersList.getRowCount()}"/>
                               </rich:column>
                               <rich:column>
                                    <f:facet name="header"><h:outputText value="Hierarchy"/></f:facet>     
                                    <h:outputText value="#{param[0].caption}"/>
                               </rich:column>
                               <rich:column>
                                    <f:facet name="header"><h:outputText value="Hierarchy"/></f:facet>     
                                    <h:inputText value="#{param[1].paramValue}"/>
                               </rich:column>
                               <rich:column>
                                    <f:facet name="header"><h:outputText value="Hierarchy"/></f:facet>     
                                    <h:outputText value="#{param[0].dataType}"/>
                               </rich:column>
                                                                                      
                                         
                     </rich:dataTable>               
                </a4j:form>



      Also been trouble-shooting this scenario where the dataTable is populated by data from a non-trivial ListDataModel (the createQuery() is based on more than one entity class, so I have to deal with Object[]).


      I have got this working for a similar situation in another Seam project but that one did not use @Factory.  The funny thing is the @Factory was working for a while this morning so not sure what triggered this.


      The problem is the populateParameters() is not executing when the JSF is rendered.  The only logical reason this could happen is if the instance variable for the List is not null.  But the SFSB is conversation-scoped so when I launch a new tab in IE to test, this concern should be irrelevant (i.e. new conversation per tab/window).


      Here is the entire backing bean method of concern:


      @Factory("populateParametersList")
           public void populateParameters(){
                //testing
                          
                populateParametersList = entityManager.createQuery("select lpm, lvp "+
                                                                                 " from ListValue lv, ListValueParam lvp, ListParamMetaData lpm "+
                                                                                 " where lv.listValueId = lvp.listValue.listValueId "+
                                                                                 " and lv.list.listId = lpm.list.listId "+
                                                                                 " and lpm.paramName = lvp.paramName "+
                                                                                 " and lvp.listValue.listValueId = 4 "+
                                                                                 " and lv.list.listId = 2")
                                                                                 .getResultList();
                
                if (populateParametersList != null && populateParametersList.size() > 0) {
                     Object[] objArray1 = (Object[])populateParametersList.get(0);
                     Object[] objArray2 = (Object[])populateParametersList.get(1);
                     
                     ListParamMetaData lpm1 = (ListParamMetaData)objArray1[0];
                     ListValueParam lvp1 = (ListValueParam)objArray1[1];
                     
                     log.info("lpm1.caption = "+lpm1.getCaption());
                     log.info("lvp1.paramValue = "+lvp1.getParamValue());
                     log.info("lpm1.dataType = "+lpm1.getDataType());
                     
                     ListParamMetaData lpm2 = (ListParamMetaData)objArray2[0];
                     ListValueParam lvp2 = (ListValueParam)objArray2[1];
                     
                     log.info("lpm2.caption = "+lpm2.getCaption());
                     log.info("lvp2.paramValue = "+lvp2.getParamValue());
                     log.info("lpm2.dataType = "+lpm2.getDataType());
                }
                          
                log.info("populateParametersList.size() = "+populateParametersList.size());
           }



      Before when the method was being called, the data was not rendering in the JSF/dataTable (but I guess that's another problem).