datatabe lazy, how to prevent the call for next load method?

UI Components for JSF
Post Reply
User avatar
daniel_r
Posts: 199
Joined: 02 Mar 2009, 16:35

10 Oct 2012, 14:24

Hi

I got some scenario in which I have to update the WrappedData of the lazy datatable manually , like this : lazyModel.setWrappedData(someCustomList) , and I want to display the new updated table content to client

The problem is that after I set the lazyModel.setWrappedData(someCustomList); the load method of the LazyDataModel obejct is called and get the old data to the table

My question is : how can I prevent the next execution of the load method ? I mean , I know that the data (getWrappedData()) will return the right value , so , can I "tell the table" to use the getWrappedData() instead of the load method? only once?

Right now I'm setting a boolean inside the LazyDeviceDataModel and checking it inside the load method , if its true , I'm returning this.getWrappedData(); and changing the boolean to false...

Thanks ahead

Daniel.
Primefaces 3.4 , MyFaces 2.0.11
Tomcat 6
Win7 32bit

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

10 Oct 2012, 16:28

sounds like a good solution

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

10 Oct 2012, 16:31

kukeltje wrote:sounds like a good solution
I agree. I was going to say something similar minutes ago. :)
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

rfwalker@hotmail.com
Posts: 1
Joined: 17 Aug 2018, 17:17

17 Aug 2018, 18:13

i know this is way old, but maybe it can help someone.

i am calling load manually in a action method kicked off from p:commandButton. I am having same issue where load() is called a second time after my manual call to load(), because internally primefaces is calling load() again as a result of this snippet in DataTable's loadLazyData() method seen below. the full stack of the second time load() is called seems to indicate it doing some pre-rendering as a result of some visitTree logic.

Code: Select all

DataTable.loadLazyData() {
....
	 if(this.isMultiSort())
        	data = lazyModel.load(first, getRows(), getMultiSortMeta(), getFilters());
        else
		data = lazyModel.load(first, getRows(), resolveSortField(), convertSortOrder(), getFilters());
...
}
to give some code to daniel_r 's explanation, this is what i did

im on primefaces 6.2
i created my overridden LazyDataModel and added a boolean property modelhasBeenSetAlready

Code: Select all

class MyLazyDataModel extends LazyDataModel<MyObject> 
{
	....
	public boolean modelhasBeenSetAlready = false;
	....
	    @Override
	    public List<MyObject> load(int first,int pageSize,String sortField,SortOrder sortOrder,Map<String,Object> filters) 
	    {
	    	if(modelhasBeenSetAlready)
	    	{
	    		modelhasBeenSetAlready = false;
	    		return this.getWrappedData();
	    	}
	    	....
	    	// after db query to populate dataSource
	    	this.setWrappedData(datasource);
	    	// setting this to true because load() will be called a 2nd time and 
	    	// i just want to return data that was just set. 
	    	// (2nd time load is called my filters are not correct and 
	    	// I dont get the correct behavior)
	    	modelhasBeenSetAlready = true;
	    	...
	    	
I have a p:commandButton's action property mapped to my method

Code: Select all

public void filterMyTable() { 
...
   ((MyLazyDataModel)myLazyModel).modelhasBeenSetAlready = false;
    myLazyModel.load(...)
}

in my backing bean which is supposed to filter the dataTable based on UI input values
from the user.

this seems to be working good for now
hope it helps someone

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

20 Aug 2018, 10:15

Thanks for the update

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 22 guests