Primefaces动态列不适用于延迟加载

时间:2014-10-24 16:58:56

标签: jsf-2 primefaces datatable lazy-loading dynamic-columns

我正在使用PF 5.0,JSF 2.0(Mojarra),Spring Webflow 2.3。我在使用Datatable Lazy加载时面临多个问题。

a。)当我尝试为DataTable组件使用具有延迟数据模型的列进行多重选择时,当我为数据表启用单选时,它可以正常工作。 b。)我面对Datatable的另一个问题是我无法使用Lazy Data表加载动态列,它曾经适用于非Lazy版本。

欢迎任何解决这些问题的建议。请找到以下代码。

    <p:dataTable id="docsTable" var="document"
               value="#{datasource}" lazy="true" paginator="true" dynamic="true"
               rows="#{searchActionBean.maxRows}" paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
               rowsPerPageTemplate="10,25,50,100" rowKey="#{document.ID}"
               sortMode="single" resizableColumns="true" scrollable="true" scrollHeight="350" >

   <f:facet name="header">
         <p:toolbar>
            <f:facet name="left">         
            <p:commandButton type="button" title="Print" icon="ui-icon-print" />
            <span class="ui-separator">
                <span class="ui-icon ui-icon-grip-dotted-vertical" />
            </span>
            <p:commandButton id="reptoggler" value="Reports" action="reportsAction"  icon="ui-icon-note">
           <f:param name="stdReportName" value="reportsMain" />
            </p:commandButton> 
            </f:facet>

            <f:facet name="right"> 
            <h:outputText value="#{searchActionBean.domainName}"   />(<h:outputText value="#{searchActionBean.resultCount}"   />) 
            <span class="ui-separator">
                <span class="ui-icon ui-icon-grip-dotted-vertical" />
            </span>
            <h:commandLink>
                     <img src="${request.contextPath}/images/excel.png" width="15" height="15" />
                     <p:dataExporter type="xls" target="docsTable" fileName="documents" />
         </h:commandLink>
          <span class="ui-separator">
                <span class="ui-icon ui-icon-grip-dotted-vertical" />
            </span>
            <h:commandLink>
                     <img src="${request.contextPath}/images/pdf.png" width="15" height="15"/>
                     <p:dataExporter type="pdf" target="docsTable" fileName="documents" />
         </h:commandLink>
             <span class="ui-separator">
                <span class="ui-icon ui-icon-grip-dotted-vertical" />
            </span>
           <p:commandButton id="toggler" type="button" value="Columns" icon="ui-icon-calculator" />
            <p:columnToggler datasource="docsTable" trigger="toggler" />   
            </f:facet> 
              </p:toolbar>


    </f:facet>            

          <p:column selectionMode="multiple" style="text-align:center; width:25px">
                  <f:facet name="header">
                     <h:outputText value="Select" />
                  </f:facet>
         </p:column>

       <p:columns value="#{searchResultsColumns}" var="column" styleClass="wrap" width="#{column.width}" columnIndexVar="colIndex" sortBy="#{document[column.pfResColumnName]}" filterBy="#{document[column.pfResColumnName]}">
               <f:facet name="header">
                      <h:outputText value="#{column.displayResultColumnName}" />
               </f:facet>                         
                  <h:outputText value="#{document[column.pfResColumnName]}" rendered="#{column.resColumnType eq 'DATE'}">
                  <f:convertDateTime pattern="MM/dd/yyyy" />
                  </h:outputText>
                  <h:outputText value="#{document[column.pfResColumnName]}" rendered="#{column.resColumnType eq null}" />
                  <h:outputText value="#{document[column.pfResColumnName]}" rendered="#{column.resColumnType eq 'SPL'}">
                  <f:converter converterId="gov.nih.nci.ctep.idart.converters.SplConverter"></f:converter>
                  </h:outputText>               
           </p:columns>
   </p:dataTable>

和Bean代码一样,我已经验证了Collections searchResultColumns不为空。

public class SearchActionBean extends LazyDataModel<DocumentResultDTO> implements Serializable
{
private List<DocumentResultDTO> datasource;


   @Override
   public DocumentResultDTO getRowData(String rowKey) {
      for (DocumentResultDTO doc : datasource) {
         if (doc.getID().equals(rowKey))
            return doc;
      }
      return null;
   }

   @Override
   public Object getRowKey(DocumentResultDTO doc) {
      return doc.getID();
   }

   @Override
   public List<DocumentResultDTO> load(int first, int pageSize, String sortField,
         SortOrder sortOrder, Map<String, Object> filters) {
      datasource = new ArrayList<DocumentResultDTO>();
        /*this.execute();*/
      commonQueriesLocal = ejbService.getCommonQueriesLocal();
      srchDelegate = new SearchDelegate();
      super.setSearchDelegate(srchDelegate);
       try
          {
             //Set the visibility of all the columns depending on the JQuery table visibility setting from the client side
              String invisibleColNames = request.getParameter("invisibleColNames");
              ArrayList<UserResultColumnDTO> dispCols = getDisplayColumns();
              ApplicationUtils.markVisibilityForColumns(dispCols,invisibleColNames);

              int iSortColumnIndex = 1;
              String sSortDirection = sortOrder.toString().equalsIgnoreCase("ASCENDING") ? "asc" : "desc";

              if(request.getParameter("iSortCol_0") != null)
                  iSortColumnIndex = Integer.parseInt(request.getParameter("iSortCol_0"));
              Query query =
                  (Query) request.getSession().getAttribute(IdartWebGlobalConstants.USER_QUERY);

              if(request.getSession().getAttribute("executeSavedQuery") != null &&
                 request.getSession().getAttribute("executeSavedQuery").toString().equalsIgnoreCase("true")
                )
                pageSize = query.getUserQuery().getPageCount();
              else
                query.getUserQuery().setPageCount(pageSize);

              query.getUserQuery().setSortOrder(sSortDirection);
              setDataSortColumn(iSortColumnIndex, getDomainNameToSetSortColumn(query.getName()), query);
              performNavigation(pageSize, first);
              // Save the query object in session

              if(getDomainName().equalsIgnoreCase("DOCUMENTS"))
              {       
                 setSearchResults((ArrayList)request.getAttribute("documentResults"));         
                 setSearchResultsColumns(dispCols);
              } 

              System.out.println("search Result "+searchResults.size());
              System.out.println("search Columns "+dispCols.size());

              // process on filters to be displayed
              customizeFilterResults();


          }
          catch(Exception ex)
          {
              log.error("-- GetData Method Error "
              + ex.getMessage()
              + " --", ex);
          }

      datasource= getSearchResults();
      System.out.println("first "+first+" pageSize "+pageSize+" sortField "+sortField+" sortOrder "+sortOrder);
        System.out.println("searchResultsColumns"+datasource);
        System.out.println("searchResultsColumns "+searchResultsColumns);
        System.out.println("GET searchResultsColumns "+getSearchResultsColumns());

      // rowCount
      int dataSize = datasource.size();
      this.setRowCount(Integer.parseInt(getResultCount()));
      return datasource;

   }
}

0 个答案:

没有答案