Search code examples
javaaws-lambdavaadinlazy-loadingvaadin8

Changing default limit in Vaadin 8 lazy loading with grid


I have implemented lazy loading in Vaadin 8 with grid implementation.

My backend runs on AWS Lambda which has a limit of 6 MB in response object.

The lazy loading implementation gives default limit(40) to server which makes my program crash giving error as "body too large".

I want to make changes in default limit of lazy loading in Vaadin.

Below is my code snippet:

grid.setDataProvider((sortorder, offset, limit) -> {

            try {
                return billingClient.getInvoiceListByCriteria(criteria, (long) offset, (long) limit).stream();
            } catch (Exception e) {
                logger.error("Exception while getInvoiceListByCriteria", e);
                return null;
            }
        }, () -> {

            try {
                totalInvoices = billingClient.getCountInvoiceListByCriteria(criteria).longValue();
                Integer count = totalInvoices.intValue();
                if (count == 0)
                    Notification.show("No Invoices found.", Notification.Type.HUMANIZED_MESSAGE);
                return count;
            } catch (Exception e) {
                logger.error("Error occured while getting count calling getCountInvoiceListByCriteria", e);
                Notification.show("Error while getting count", Notification.Type.ERROR_MESSAGE);
                return null;
            }

        });

Solution

  • The problem is resolved by manually changing the value of limit.

    grid.setDataProvider((sortorder, offset, limit) -> {
    
            try {
                limit=20;
                return billingClient.getInvoiceListByCriteria(criteria, (long) offset, (long) limit).stream();
            } catch (Exception e) {
                logger.error("Exception while getInvoiceListByCriteria", e);
                return null;
            }
        }, () -> {
    
            try {
                totalInvoices = billingClient.getCountInvoiceListByCriteria(criteria).longValue();
                Integer count = totalInvoices.intValue();
                if (count == 0)
                    Notification.show("No Invoices found.", Notification.Type.HUMANIZED_MESSAGE);
                return count;
            } catch (Exception e) {
                logger.error("Error occured while getting count calling getCountInvoiceListByCriteria", e);
                Notification.show("Error while getting count", Notification.Type.ERROR_MESSAGE);
                return null;
            }
    
        });
    

    offset is adjusted according to limit I have set.