Viritin - using SortableLazyList with FilterableListContainer

I’ve been trying to get this to work for days and would appreciate any help.

​SortableLazyList sll = new SortableLazyList<>(new SortableLazyList.SortablePagingProvider() {

@Override
public List findEntities(int firstRow, boolean sortAscending, String property) {
List l = demoData.subList(firstRow, demoData.size());
l.sort(new Comparator() {

@Override
public int compare(DemoBean arg0, DemoBean arg1) {
if (“id”.equals(property)) {
return Integer.compare(arg0.getId(), arg1.getId()) * (sortAscending ? 1 : -1);
}
return 0;
}

});

return l;
}
}, new CountProvider() {

@Override
public int size() {
return demoData.size();
}

});

final FilterableListContainer lc = new FilterableListContainer(sll);

MGrid t = new MGrid<>();
t.setContainerDataSource(lc);

Whenever I try to sort the container, I get
java.lang.UnsupportedOperationException
at java.util.AbstractList.set(Unknown Source)
at java.util.AbstractList$ListItr.set(Unknown Source)
at java.util.List.sort(Unknown Source)
at java.util.Collections.sort(Unknown Source)
at org.vaadin.viritin.ListContainer.sort(ListContainer.java:365)
at org.vaadin.viritin.FilterableListContainer.sort(FilterableListContainer.java:185)
at package.CustomTableDemoLayout$14.sort(CustomTableDemoLayout.java:270)

Any ideas?

Hi,

do anyone (especially Matti) know how to solve this issue?

I am also not able to filter the MTable

    SortablePagingProvider<People> pageProvider = new SortablePagingProvider<People>() {

      @Override
      public List<People> findEntities(int firstRow, boolean ascending, String sortField) {

        return peopleCollector.collect(ascending, sortField, filters);
      }
    };

    CountProvider countProvider = new CountProvider() {

      @Override
      public int size() {
        return peopleCollector.countPeople();
      }
    };

    peopleOverviewTable.lazyLoadFrom(pageProvider, countProvider, pageSize);

Error:

java.util.NoSuchElementException: null
    at java.util.AbstractList$Itr.next(AbstractList.java:364)
    at java.util.SubList$1.next(AbstractList.java:707)
    at java.util.AbstractCollection.toArray(AbstractCollection.java:141)
    at java.util.ArrayList.<init>(ArrayList.java:177)
    at org.vaadin.viritin.LazyList.subList(LazyList.java:290)
    at org.vaadin.viritin.ListContainer.getItemIds(ListContainer.java:120)
    at com.vaadin.ui.Table.getItemIds(Table.java:2271)
    at com.vaadin.ui.Table.getVisibleCellsNoCache(Table.java:2221)
    at com.vaadin.ui.Table.refreshRenderedCells(Table.java:1745)
    at com.vaadin.ui.Table.enableContentRefreshing(Table.java:3276)
    at com.vaadin.ui.Table.changeVariables(Table.java:3118)
.
.
.

Hi,

I have missed the original post to this tread as well, so let’s anser that first. I’m not bit fan of FilterableListContainer (or Container.Filterable to be more specific) as it kind of move the filtering logic for Vaadin components to handle, making it hard for developer to customize how the filtering actually works. I bet the implementation of FilterableListContainer don’t work with lazy list. Instead you should get the filtering from your apps UI and reset the lazy loading strategies with ones that take in the filters.

I think the issue with suitup’s code is in implementation of CountProvider. That should also take into account the filter, not just the PagingProvider, otherwise they are out of sync causing issues when Table tries to update its row cache.

cheers,
matti

Hi,
I was trying to implement MTable with LazyLoading but getting NoSuchElementException. Here is my code.

private List<String> getList(){ final ArrayList<String> strings = new ArrayList<>(); strings.add("a"); strings.add("b"); strings.add("c"); strings.add("d"); strings.add("e"); strings.add("f"); strings.add("g"); strings.add("h"); return strings; } List<String> global = getList(); MTable mTable = new MTable( new LazyList.PagingProvider<String>() { @Override public List<String> findEntities(int firstRow) { return findAll(firstRow,5,global); } }, new LazyList.CountProvider() { @Override public int size() { return getList().size(); } }); [code]
private List findAll(int start , int max,List dummyList){

    int end = (int) (start + max);
    if (end > dummyList.size()) {
        end = dummyList.size();
    }
    return dummyList.subList(start, end);
}

[/code]When I give LazyList.DEFAULT_PAGE_SIZE as second parameter in findAll() function then it works perfectly. But if I give 5 or something less than 45 then it throws this exception.

java.util.NoSuchElementException at java.util.AbstractList$Itr.next(AbstractList.java:364) at java.util.SubList$1.next(AbstractList.java:707) at java.util.AbstractCollection.toArray(AbstractCollection.java:141) at java.util.ArrayList.<init>(ArrayList.java:177) at org.vaadin.viritin.LazyList.subList(LazyList.java:294) at org.vaadin.viritin.ListContainer.getItemIds(ListContainer.java:150) at com.vaadin.ui.Table.getItemIds(Table.java:2278) at com.vaadin.ui.Table.getVisibleCellsNoCache(Table.java:2224) at com.vaadin.ui.Table.refreshRenderedCells(Table.java:1747) at com.vaadin.ui.Table.getVisibleCells(Table.java:4075) at com.vaadin.ui.Table.beforeClientResponse(Table.java:3289) at com.vaadin.server.communication.UidlWriter.write(UidlWriter.java:112) at com.vaadin.server.communication.UidlRequestHandler.writeUidl(UidlRequestHandler.java:124) at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:92) at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41) at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1436) at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:380) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:305) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:169) at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:232) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316) at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:160) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283) at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571) at java.lang.Thread.run(Thread.java:745) Any ideas ? what am I doing wrong ?

I haven’t look deeply into your code, but due to my own experience I’m suspecting that these NoSuchElementException exceptions are due to a bad/wrong implementation in your countPeople() method (whose source code is not visible here, either).

As I was suffering too from these exceptions, it took me a while to realize that my count method (or my size() implementation inside CountProvider) was always returning a plain database COUNT(*), while in fact it should be returning the count of the filtered data set it you are implementing any kind of filtering.

Please check if that may be your case.

I think Pere is right here. Your findAll method seem to sanitize the end index properly, so the MTable must be requesting a page that start beyond the end of your list.

BTW. I guess you are just prototyping with it currently, but wanted to underline that lazy binding don’t help you to save any memory, if your data is in JVM memory anyways as in your and mine example. The real queries must happen in the DB layer.

cheers,
matti