Vaadin 14含组件Notification搭配@PreserveOnRefresh刷新后异常
Vaadin 14.8.14中@PreserveOnRefresh与自定义Notification的布局异常问题
在Vaadin 14.8.14版本中,使用@PreserveOnRefresh注解的路由布局里,创建一个duration=0(无自动关闭)且包含自定义组件的Notification时,出现以下异常表现:
- 页面首次加载时,Notification与页面布局显示均正常;
- 刷新浏览器标签后,页面布局的第一个组件会替换Notification内的原有布局;
- 若Notification仅设置纯文本内容(如调用
notification.setText("notif")),则刷新后无异常。
示例代码
@PreserveOnRefresh @Route("test") public class TestPanel extends Div{ public TestPanel() { TextField username = new TextField("username"); PasswordField password = new PasswordField("password"); password.setPlaceholder("password"); VerticalLayout mainVerticalLayout = new VerticalLayout(username,password); add(mainVerticalLayout); Notification notification = new Notification(); notification.setDuration(0); HorizontalLayout notifLay = new HorizontalLayout(new Text("zalakladka"),new Button("btn")); notification.add(notifLay); notification.open(); } }
状态展示
页面初始显示状态:
页面刷新后显示状态:
若将页面布局嵌套一层后:
VerticalLayout mainVerticalLayout = new VerticalLayout(username,password); VerticalLayout firstlayout = new VerticalLayout(mainVerticalLayout); add(firstlayout);
此时页面刷新后显示状态:
疑问
该问题为何会发生?这是Vaadin的预期行为吗?
内容的提问来源于stack exchange,提问作者Miłosz Bąbliński
相关产品推荐
相关产品推荐

