You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 10:28:22