更新Vaadin网格中的数据 [英] Updating data in Vaadin's grid

查看:258
本文介绍了更新Vaadin网格中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我的问题是我的网格没有更新数据。



我有一个线程可以从数据库获取新值,但是当我将新DataProvider从获得新值的集合中获取,网格不会改变任何东西。



例如,Grid包含来自客户端的订单,每30秒一次Thread search if有新的订单可用,然后y获得ArrayList中的所有订单,并在网格的DataProvider中设置新的ArrayList,但Grid继续保持与以前相同的值。



如何刷新网格中的数据而无需刷新所有网页?



对不起,我的英语



感谢

解决方案

民意调查您可以设置浏览器以检查服务器是否有给定间隔的更新。例如,如果您希望浏览器每30秒更新一次,那么您可以像这样启用轮询。例如,如果您希望浏览器每30秒更新一次,则可以像这样启用轮询:

  MyUI ui = getMyUi(); 
ui.setPollInterval(30000);
if(ui.isPollListenerRegistered()){
注册r = ui.addPollListener(this :: reloadFromDatabase);
ui.setPollRegistration(r);

将pollInterval设置为大于-1的值可以使浏览器使用给定的服务器延迟。添加一个轮询监听器可以让你注意到服务器上的这些检查以及从数据库加载。



如果只有一个页面需要像这样刷新,那么添加导航监听器以及可以设置轮询时间间隔返回-1,以便其他页面不发送不必要的轮询事件。

  MyUI ui = getMyUi(); 
ui.setPollInterval(-1);
if(ui.isPollListenerRegistered()){
ui.getPollRegistration()。unregister();
}

Vaadin wiki中有一些文档,但是您不需要后台线程if您可以从数据库读取值。



https:
$ b

使用Vaadin Push,您可以在后台更新数据,然后仅请求应更新以刷新的客户端。这使您可以优化请求,因为客户端不会进行不必要的轮询。您还可以从Web服务获取数据,然后使用相同的数据更新所有客户端。



您可以在Vaadin文档中阅读更多信息:



https:// vaadin.com/docs/-/part/framework/advanced/advanced-push.html



我推出了一个示例项目,演示如何使用单个重复后台线程来更新数据,然后用它更新网格的内容。对于完整的推送示例,不仅仅是几行代码,因此您可以在这里找到代码:

https://github.com/m1kah/vaadin-grid-push


Hello everyone my problem is that my grid doesn't update data.

I've a Thread that get new values from a database but when I assign the new DataProvider from the collection that get new values, the grid doesn't change anything.

For example, the Grid contains the orders from clients, every 30 seconds a Thread search if there are new orders available, then y get all the orders in an ArrayList and set the new ArrayList in the grid’s DataProvider but the Grid continues having the same values as before.

How can I refresh data in the Grid without refresh all the web page?

Sorry for my English

Thank you.

解决方案

Poll

You can set browser to check servers for updates with given interval. I have added couple of code samples how to use poll interval for this.

For example, If you want the browser to update every 30 seconds then you can enable polling like this:

MyUI ui = getMyUi();
ui.setPollInterval(30000);
if (ui.isPollListenerRegistered()) {
    Registration r = ui.addPollListener(this::reloadFromDatabase);
    ui.setPollRegistration(r);
}

Setting pollInterval to value greater than -1 makes browser to call server with the given delay. Adding a poll listener allows you to notice these checks on server and load from database.

If only 1 page needs to refresh like this then add navigation listener as well which can set poll interval back to -1 so that other pages do not send unnecessary poll events.

MyUI ui = getMyUi();
ui.setPollInterval(-1);
if (ui.isPollListenerRegistered()) {
    ui.getPollRegistration().unregister();
}

There is some documentation in Vaadin wiki but you do not need a background thread if you can read values from database.

https://vaadin.com/wiki?p_p_id=36

Push

Using Vaadin Push you can update data in the background and then request only clients that should be updated to refresh. This allows you to optimise requests because clients do not do unnecessary polling. You can also have single request to get data from web service and then update all clients with the same data.

You can read more in Vaadin documentation:

https://vaadin.com/docs/-/part/framework/advanced/advanced-push.html

I pushed an example project that shows how to use a single repeating background thread to do updated to data and then update contents of a grid with it. There are more than just a few lines of code for a complete push example so you can find the code here:

https://github.com/m1kah/vaadin-grid-push

这篇关于更新Vaadin网格中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆