Issues with Lazy Datatable

UI Components for JSF
Post Reply
Antarix.Prime
Posts: 1
Joined: 22 Oct 2014, 15:53

23 Oct 2014, 16:22

Hi,

I am using PF 5.0, JSF 2.0 (Mojarra), Spring Webflow 2.3. I am facing multiple issues with the Datatable Lazy loading.

a.) When I try to have Multiple Select for Columns with Lazy Data Model for the DataTable component, When I enable single select for Data table , it works fine .
b.) Another issue that I am facing with the Datatable is that I am unable to load dynamic columns with Lazy Data table , It used to work fine for the non-Lazy version.

Any suggestions to resolve these issues are welcome. Please find the code below.

Code: Select all

<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>
And the Bean code, I have verified that the Collections searchResultColumns is not empty.

Code: Select all

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

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

24 Oct 2014, 10:43

Hi,

Thanks for in itself an extensive and fairly complete post. On thing you should keep in mind though for next posts, is that two separate posts with more explicit subjects would:
- make it easier for others to find related posts based on the subject ('issues with lazy datatable' is kind of generic/common)
- would make it easier for us to reply on specific issues rather than answers getting mixed.

Now down to the issues themselves. You could (should, always first) try to check if this is a previously known issue by either/or
- checking the issue list for fixed/known/... issues
- trying a newer version of PF (5.0.x, 5.1, 5.1.x) to see if it is fixed there
The reason I mention those is that I think I rember (not 100% sure) that there were related issues.

Cheers

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 32 guests