Table - lazy loading

Hi!

What ways are recommended to implement lazy loading for the Vaadin table?
Does it support this from its own?
Or Do I have do use an apropriate container for the table?
How does that work with EJB?

Or is the JPAcontainer the only recommended way of implementing that?

Don’t know about THE recommended way ™, but I would choose to implement my own Container.

Any container that supports lazy loading will do. See for instance, Lazy Query Container, HBN Container, Criteria Container, JPA Container, etc.

Hm. The Vaadin table does not support lazy loading on its own then. Seems that Vaadin team does not have written a guide on that either.

Anyway, thanks for your help.
I have my EJB layer in place, from a previous application implementation.

How can I use the “Lazy Query Container” add-on then? I have my beans already in a list, which I would like to hand out directly to the container that is attached to the table. Possible?

Seems Vaadin is not completely sure on that then self: TreeTable supports lazy loading as per:
https://vaadin.com/api/framework/com/vaadin/ui/TreeTable.html
But table does not support that (setLazyLoading) as per:
https://vaadin.com/api/framework/com/vaadin/ui/Table.html

Hm.

For the records (Vaadin 6.7.8):

java.lang.UnsupportedOperationException: Lazy options loading is not supported by Table.
at com.vaadin.ui.Table.setLazyLoading(Table.java:4293)

Hopefully the IndexedConainer will do it - anyone knows if TreeTable supports lazy-loading out of the box?

As Jean-François Lamy already answered you will need a container that supports lazy loading. That kind of containers are for example
JPAContainer
, SQLContainer and
Lazy Query Container
. IndexedContainer is just an in-memory container. If you have EJBs then the Lazy Query Container is the way to go. Unfortunately I haven’t used it myself.

Both TreeTable and Table work with lazy loading containers. In Table and TreeTable, there is also lazy loading on how rows are transferred from server to browser. If you have lots of rows in your Table, only a small amount of rows is transferred at a time. And when user scrolls to a certain position, the rows visible at the position are loaded from the server to the browser. See methods
setPageLength
,
setCacheRate
.

EDIT: I created a ticket about the setLazyLoading method.

Thank you very much for creating the ticket!!
Could you please post a code-snippet on how I then best can display my List that I already have from the middleware layer with a Vaadin table using Lazy Query Container?
I dont want to run the queries from the UI layer - data is already in place and provided by the middleware.

I also measured where time goes, and it is NOT at picking the data from the database, and it is NOT sending the page to the client. Time goes when table/container is populated - which is way too slow for using that in production.

i know this might to late, but maybe would help other readers…

just found that there’s the JPA example hosted on github by the author ot LazyQUeryCOntainer. a snippet from it:


private EntityContainer entityContainer = new EntityContainer(entityManager, true, true, true, Task.class, 100, new Object[] { “name” }, new boolean[]
{ true });
entityContainer.addContainerProperty(“taskId”, Long.class, 0L, true, true);
Task entity = entityContainer.addEntity();
entity.setName(“task-” + Integer.toString(1));
entityContainer.commit();
table.setPageLength(6);
table.setContainerDataSource(entityContainer);

direct URL:
https://github.com/tlaukkan/vaadin-lazyquerycontainer/blob/master/vaadin-lazyquerycontainer-jpa-example/src/main/java/org/vaadin/addons/lazyquerycontainer/example/jpa/VaadinApplication.java

cheers

However i get a nice ConcurrentModificationException, when trying to access the DAL using my own GenericDAO instead of using the LazyQueryFactory built-in
LazyQueryContainer API.
i m trying to load some dummy data into the Customer Entity created using JPA, and within the click Listener i’m calling my generic dao which returns a list of
entities/items, which i use to populate the EntityContainer Instance.
However at creation the EntityContainer needs a default NO-ZERO argument( else a nice Math Exception is thrown… ), and what i’m thinking is that LQC at instantiation
it builds the container and populates it, rather than when i am clicking the “get-customers-button”.
Here’re some snippets:

    Table customerTable = new Table("All Customers Table");
    entityContainer = new EntityContainer<>(entityManagerShared, true, true, true, Customer.class, 1, new Object[]{FIRST_NAME}, new boolean[]

{true});
entityContainer.addContainerProperty(LazyQueryView.PROPERTY_ID_ITEM_STATUS, QueryItemStatus.class, QueryItemStatus.None);
entityContainer.addContainerProperty(ID, Long.class, 0);
entityContainer.addContainerProperty(FIRST_NAME, String.class, “”);
entityContainer.addContainerProperty(LAST_NAME, String.class, “”);

    customerTable.setContainerDataSource(entityContainer);

And my Listener
@Override
public void buttonClick(Button.ClickEvent event) {
if(event.getButton() == getCustomerButton) {
List allCustomers = customerDAO.findAll(Customer.class);
for(Customer eachCustomer : allCustomers) {
entityContainer.addItem(eachCustomer);
}

    } else if(event.getButton() == resetFormButton) {
        entityContainer.removeAllItems();
    }
}

Now when the deploy is done and app is started, the ConcurrentModif Exception is thrown.
Any help is appreciated!