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.
datatabe lazy, how to prevent the call for next load method?
-
- Posts: 6144
- Joined: 10 Sep 2011, 21:10
I agree. I was going to say something similar minutes ago.kukeltje wrote:sounds like a good solution
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
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
-
- Posts: 1
- Joined: 17 Aug 2018, 17:17
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.
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
I have a p:commandButton's action property mapped to my method
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
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());
...
}
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;
...
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
-
- Information
-
Who is online
Users browsing this forum: Google [Bot] and 22 guests