1 Reply Latest reply on Jun 30, 2011 4:44 PM by Michael Hughes

    Cannot add new row to rich:dataTable after a search and add

    Michael Hughes Newbie

      Having problems adding new data from a search function to a rich:dataTable. In its current state, it only shows one result at a time after clicking the "Add" button. Using JBoss 4.2.2.GA, RichFaces 3.3.3, Seam 2.1.2, JSF 1.2

       

      My xhtml that includes the "Add" button and rich:dataTable

       

         
           <ui:decorate template="/layout/ButtonVerticalDisplay.xhtml">
               <ui:param
                    name="label"
                    value=" " /> 
               <h:commandButton 
                    id="search"
                    value="#{messages['Add']}"
                    action="BullReport.xhtml" />
          </ui:decorate>
          
          <rich:panel 
              width="1000"
              id="RP_infoReportDataList"
            rendered="#{((!empty infoDataList.infoData.name and 
                !empty infoDataList.infoData.id.infoCode) or 
                (!empty infoDataList.infoData.id.infoCode and
                !empty infoDataList.infoData.id.registrationNumber) or 
                (!empty infoDataList.infoData.name and 
                !empty infoDataList.infoData.id.registrationNumber))
                and !empty infoDataList.singleResult }">     
                
              <h:form id="formInfoReportResults">     
                              
              <rich:dataTable 
                  id="infoReportTable"
                  width="980" 
                  cellpadding="0" 
                  cellspacing="0" 
                  border="0"
                  value="#{infoReportList.addedInfoList}"
                  var="report"
                  rowKeyVar="rowNum">
              
                  <f:facet name="header">
                      <rich:columnGroup>
                          <rich:column>
                              <h:outputText value="#{messages['Compare']}" />
                          </rich:column>
                          <rich:column>
                              <h:outputText value="#{messages['Remove']}" />
                          </rich:column>
                          <rich:column>
                              <h:outputText value="#{messages['RegistrationNumber']}" />
                          </rich:column>
                          <rich:column>
                              <h:outputText value="#{messages['Name']}" />
                          </rich:column>
                          <rich:column>
                              <h:outputText value="#{messages['InfoCode']}" />
                          </rich:column>
                      </rich:columnGroup>
                  </f:facet>
                  
                  <rich:columnGroup>
                      <rich:column style="text-align: center">
                          <h:selectBooleanCheckbox />
                      </rich:column>
                      <rich:column style="text-align: center">
                          <h:selectBooleanCheckbox />
                      </rich:column>
                      <rich:column width="75" style="text-align: center">
                          <h:outputText value="#{report.id.registrationNumber}" />
                      </rich:column>
                      <rich:column width="75" style="text-align: center">
                          <h:outputText value="#{report.id.infoCode}" />
                      </rich:column>
                      <rich:column width="75" style="text-align: left">
                          <h:outputText value="#{report.name}" />
                      </rich:column>
                  </rich:columnGroup>
                      
              </rich:dataTable>
      

       

      My Bean

       

      @Name("infoReportList")
      public class InfoReportList extends EntityQuery<InfoData>
      {
      
          /**
           * 
           */
          private static final long    serialVersionUID    = 1L;
          
          private InfoData infoData;
          private List<IncludedInfoData> addedInfoList;
          private InfoDataList infoDataList = new InfoDataList();
      
          private static final String EJBQL = "Select infoData From InfoData infoData";
          
          public InfoReportList ()
          {
              addedInfoList = new ArrayList<IncludedInfoData>();
              infoData = new InfoData();
              infoData.setId(new InfoDataId());
              setEjbql(EJBQL);
              setMaxResults(Integer.valueOf(250));
          }
          
          public InfoData getInfoData()
          {
              return infoData;
          }
          
          public void setInfoData(InfoData infoData) {
              this.infoData = infoData;
          }
          
          public InfoDataList getInfoDataList()
          {
              return infoDataList;
          }
          
          public void setInfoDataList(InfoDataList infoDataList)
          {
              this.infoDataList = infoDataList;
          }
      
          public void setAddedInfoList(List<IncludedInfoData> addedInfoList)
          {
              this.addedInfoList = addedInfoList;
          }
              
          public List<IncludedInfoData> getAddedInfoList()
          {
              if(addedInfoList.isEmpty())
              {            
                  int i = 0;
                  
                  while (i < infoDataList.getResultList().size())
                  {
                      InfoData selectedInfos = (InfoData)infoDataList.getResultList().get(i);
                      IncludedInfoData includedInfo = new IncludedInfoData(selectedInfos);
                      addedInfoList.add(includedInfo);
                      i++;                
                  }
                  for(Iterator<IncludedInfoData> iterator = addedInfoList.iterator(); iterator.hasNext();)
                  {
                      IncludedInfoData includedIterator = (IncludedInfoData)iterator.next();
                      List<InfoData> tempList = getResultList();
                      int j = 0;
                      
                      while (j < tempList.size())
                      {
                          InfoData infoDataIterator = (InfoData)tempList.get(j);
                          
                          if(infoDataIterator.getId().getBreed()
                                  .equals(includedIterator.getId().getName())
                                  && infoDataIterator.getId().getRegistrationNumber()
                                  .equals(includedIterator.getId().getRegistrationNumber())
                                  && infoDataIterator.getId().getInfoCode()
                                  .equals(infoDataIterator.getId().getInfoCode()))
                          {
                              addedInfoList.add(includedIterator);                        
                          }
                          j++;
                      }
                      
                  }
              }
              return addedInfoList;    
          }    
      }