使用网格更改 Vaadin 8 延迟加载中的默认限制

Changing default limit in Vaadin 8 lazy loading with grid

我在 Vaadin 8 中使用网格实现实现了延迟加载。

我的后端在 AWS Lambda 上运行,它的响应对象限制为 6 MB。

延迟加载实现为服务器提供默认限制 (40),这使我的程序崩溃并给出错误 "body too large"。

我想在 Vaadin 中更改延迟加载的默认限制。

下面是我的代码片段:

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;
            }

        });

奇怪的是40行大于6MB

从未尝试过,但您可以使用 grid.getDataCommunicator().setMinPushSize(size) 来设置最小项目数。它初始化为 40,所以我想你可以降低它以防止你的响应变大。但是名字中的"min"暗示其他因素也可能影响它,所以你需要彻底测试它。

问题已通过手动更改限制值解决。

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;
        }

    });

偏移量根据我设置的限制进行调整。