如何强制 Vaadin v8 更新屏幕?
我有一个小型 Vaadin v8 应用程序,它有多个输入字段(组合框、选择组等)。其中大部分内容由第一个 ComboBox 的所选内容决定。但是,当我选择其中的某些内容时,所有其他内容都保持空白,直到我单击一个内容,此时它们都会更新。这不是期望的行为,但我认为这是由于服务器端处于最新状态但未更新客户端视图造成的。 (即使在我的第一个 Combobox 的 ValueChangeListener 中添加 requestRepaint() 时)
即使没有单击其他组件,也必须有某种方法强制 Vaadin 获取我希望它显示的数据?
编辑 我不允许这么快发布我自己的问题的答案,所以我暂时把它放在这里:
我发现有一个 javascript 方法可以同步客户端和服务器。
myComponent.getApplication().getMainWindow().executeJavaScript("javascript:vaadin.forceSync();");
我现在遇到的唯一问题是,我的一个组合框上的 ValueChangeListener 仍然仅在我单击另一个组合框(或同一组合框两次)时才会触发。这是最奇怪的事情,因为第二个组合框在加载时会完美地触发它的事件。
I have a small Vaadin v8 application that has several input fields (comboboxes, selectgroups, etc...). The content of most of these is determined by the chosen content of the first ComboBox. However, when I select something in it, all the others stay blank until I click one, at which point they all update. This is not desired behaviour, but I assume it's being caused by the server-side being up to date but not updating the client side view. (Even when adding requestRepaint() in my first Combobox's ValueChangeListener)
There must be some method to force Vaadin to get the data I want it to display even if no other components are clicked?
EDIT
I'm not allowed to post answers to my own question so soon, so I'm putting it here temporarily:
I found that there's a javascript method that synchs client and server.
myComponent.getApplication().getMainWindow().executeJavaScript("javascript:vaadin.forceSync();");
The only problem I have now is that the ValueChangeListener on one of my comboboxes still only fires when I click another combobox (or the same one twice). It's the weirdest thing because the second combobox, when loaded, fires it's event perfectly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
第一个 ComboBox 是否处于“立即”模式?
如果不是,它可能应该是:component.setImmediate(true)。
请参阅https://vaadin.com/book/-/page/components.selection。 html
Is the first ComboBox in "immediate" mode?
If not, it probably should be : component.setImmediate(true).
See https://vaadin.com/book/-/page/components.selection.html
我遇到了同样的问题,请参阅下面如何在版本 8.0.5(从 2017 年开始)中完成它:
I had the same problem, see below how it could be done in version 8.0.5 (from 2017):
如果您为组件设置了强制 vaadin 重新渲染它们的数据源,则可以使用一个 hack。我用它来更新具有动态数据的表
There is a hack you can use if you have set a datasource for your componets that forces vaadin to re-render them. I use this for updating tables that have dynamic data
您是否请求在正确的组件上重新绘制?
请记住,
requestRepaint
将组件标记为脏,但并不意味着它将被重新绘制 - 客户端只有在向服务器发出请求时才能刷新。请参阅此帖子 https://vaadin.com/forum/-/message_boards/view_message/231271< /a> 有关您的选项的更多信息(它处理由于后台线程处理而导致的 UI 刷新)。
Did you requestRepaint on the correct components?
Keep in mind that
requestRepaint
marks the component as dirty but doesn't mean it will be repainted - a client can only be refreshed when it makes a request to the server.See this thread https://vaadin.com/forum/-/message_boards/view_message/231271 for more information about your options (it deals with UI refreshes due to background thread processing).
将此行放在主 UI.init(VaadinRequest) 方法中就足够了
在 Vaadin 7 中,如果您想每秒刷新 UI(在本例中),则 。通过这种方式,您可以指示 UI 轮询服务器以了解定义的时间间隔内的更改。
请注意,如果有大量用户同时使用您的应用程序,过多的服务器流量可能会成为问题。
在 Vaadin 6 中,您必须使用 ProgressIndicator(如果您愿意,它可以是不可见的),并尝试执行与 Vaadin 7 中的 UI.getCurrent().setPollInterval(int) 类似的操作。
In Vaadin 7 it is enough to put this line in main UI.init(VaadinRequest) method:
if you want to refresh your UI (in this case) every second. This way you instruct UI to poll server for changes in defined interval.
Beware, excessive server traffic might be a problem if you have lot of users that use your application at the same time.
In Vaadin 6 you will have to play with ProgressIndicator (which could be invisible if you want) and try to do the similar what UI.getCurrent().setPollInterval(int) in Vaadin 7 does.