Datatable with Custom Filtering and lazy loading not working

UI Components for JSF
vidya.ambadipudi
Posts: 4
Joined: 12 Jun 2013, 15:58

03 Jul 2014, 16:07

Hi All,

I am trying to implement custom filtering.

Following is my code.

xhtml

Code: Select all

<p:dataTable id="my-tasks-table" widgetVar="myTasksTable" var="myInfo"
		editable="true"
		value="#{fMHumanTaskGenericBean.getObjectList('my-tasks', true,'task')}"
		filteredValue="#{fMHumanTaskGenericBean.filterValues}"
		style="font-size: 9pt;" lazy="true"
		selection="#{fMHumanTaskGenericBean.selectedRows}"
		rowKey="#{myInfo.task_id}" paginator="true" rows="50"
		paginatorPosition="top" scrollable="true" scrollHeight="395"
		paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} "
		currentPageReportTemplate="Total Records : {totalRecords}">

		<p:column id="process" rendered="#{_selected.contains('process')}"
			width="221" headerText="#{bundle.process}"
			sortBy="#{myInfo.process_name}" filterBy="#{myInfo.process_name}"
			filterMatchMode="exact" style="text-align: center">
			<f:facet name="filter">
				<p:selectOneMenu onchange="PF('myTasksTable').filter()">
					<f:selectItems
						value="#{fMHumanTaskGenericBean.getFilterProcessesNamesList('my-tasks', 'task')}" />
				</p:selectOneMenu>
			</f:facet>
			<h:outputLink style="text-decoration: none !important" id="sd_"
				rel="#{myInfo.fm_process_instance_id}" class="statusDetail"
				value="#">
				<h:outputText value="#{myInfo.process_name}" />
			</h:outputLink>
		</p:column>
	</p:dataTable>
and lazy loader class - load method

Code: Select all

@Override
	public List<Map<String, Object>> load(int firstRow, int lastRow, String sortField, SortOrder sortOrder, Map filters) {
		try {
			this.dataHelper.setFirstRow(firstRow);
			this.dataHelper.setLastRow(lastRow);
			this.dataHelper.setSortField(sortField);
			this.dataHelper.setSortOrder(sortOrder.name());
			this.dataHelper.setFilters(filters);
			data = Util.convertGroovyDataToMap(dataHelper.fetchData());
			setRowCount(dataHelper.fetchFilteredCount());
		} catch (Exception ex) {
			logger.error("Error! LazyMapDataModel.load() - " + ex.getMessage(), ex);
		}
		return data;
	}
The load method never gets called onchange of filter values.
Also primefaces demo does not have an example with custom filters AND lazy loading. lazy loading eg is with normal filters :cry:
Any help is appreciated.

Thanks !
Vidya Ambadipudi

rengar
Posts: 8
Joined: 22 Oct 2012, 13:31

14 Jul 2014, 11:41

At sort and paginator occur the same when mix sort, filter and lazy.

Don't call method "load" of datamodel.

andy56_uk
Posts: 11
Joined: 17 Sep 2012, 23:10

18 Jul 2014, 14:59

Hi all,

I am also trying to implement filtering with lazy loading, but it isn't working.

Code: Select all

<h:form id="agency_type_list_form">
    <p:dataTable style="width: 30em;" id="agencyTypeTable" lazy="true"
       var="agencyType" value="#{agencyTypeController.model}"
	    paginator="true" rows="10" rowsPerPageTemplate="5,10,15"
	    paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
	    selection="#{agencyTypeController.selectedItems}"
	    filteredValue="#{agencyTypeController.filteredItems}"
	    rowKey="#{agencyType.code}">
	<p:column selectionMode="multiple" style="width:16px;text-align:center"/>
	<p:column headerText="Code" sortBy="#{agencyType.code}" filterBy="#{agencyType.code}" filterMatchMode="contains" width="20%">
	    <h:outputText value="#{agencyType.code}" />
	</p:column>
    ...
I have implemented a setFilteredItems(List<myType> items) method in my controller, and this gets called whenever I type something into the filter field on the datatable. However, the 'items' variable passed to the method by the datatable is always null.

Can anyone suggest what is going wrong please? Does filtering actually work with the lazy data model?

Is there any documentation that gives a detailed description of the datatable processing life-cycle?

@rengar

I don't understand your reply.

When using lazy loading, the LazyDataModel.load(...) method is called automatically by the datatable every time the paginator is used and every time a column is sorted.
PrimeFaces 5
JSF 2.2, JDK 1.8.0_05,
WildFly 8.1.0 (Final)
NetBeans IDE Dev (Build 201406050001)
Windows 8.1 x64

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

18 Jul 2014, 17:25

With lazy Idon't use filteredValue at all, I just dothe filtering in the load method

andy56_uk
Posts: 11
Joined: 17 Sep 2012, 23:10

19 Jul 2014, 01:37

HI, and thanks for your reply.

But how do you do that using the enhanced filtering options?

When something is entered in one of the filter fields the load method isn't called.

It just doesn't seem to work.
PrimeFaces 5
JSF 2.2, JDK 1.8.0_05,
WildFly 8.1.0 (Final)
NetBeans IDE Dev (Build 201406050001)
Windows 8.1 x64

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

19 Jul 2014, 08:03

Until PF starts passing the matchmode to the load method, I do that programatically in the load method.

https://code.google.com/p/primefaces/is ... il?id=3198
https://code.google.com/p/primefaces/is ... il?id=6756

andy56_uk
Posts: 11
Joined: 17 Sep 2012, 23:10

22 Jul 2014, 18:03

@kukeltje

Thanks again for replying.

I can now see that load(...) is getting called when a filter field is modified.

How exactly are you retrieving the filter value and filter match mode for each column in your load(...) method?

Can you provide a code example please?
PrimeFaces 5
JSF 2.2, JDK 1.8.0_05,
WildFly 8.1.0 (Final)
NetBeans IDE Dev (Build 201406050001)
Windows 8.1 x64

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

22 Jul 2014, 18:22

I unffortunately don't use thematchmode from the xhtml,I implement it injava. But you might be able to use binding and in theload method try to read the filtermatchmode from the columns

andy56_uk
Posts: 11
Joined: 17 Sep 2012, 23:10

22 Jul 2014, 19:13

OK, thanks for your time.

It looks like I'm either going to have do a major hack, or try the OpenFaces data table instead.
PrimeFaces 5
JSF 2.2, JDK 1.8.0_05,
WildFly 8.1.0 (Final)
NetBeans IDE Dev (Build 201406050001)
Windows 8.1 x64

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

22 Jul 2014, 23:31

Reading the filterMatchMode in the load method is a'hack' but imo not a major one and doable. But it might even be doable to create apatch in datatable.java. The code is cleanly written? If you create a patch, I'm interested in creating kind of special release of the datatable component hat incorporates this (and other enhancements)

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 32 guests