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

Vaadin 21 Flow迁移:替代CustomLayout实现带边框标题面板

Vaadin 7 迁移至 Vaadin 21 Flow 带边框标题面板实现方案

Vaadin Flow 21 已不再支持Vaadin 7 中基于location属性的CustomLayout旧实现,以下是两种等效实现方案:

方案1:使用原生HTML组件实现(推荐)

直接使用Vaadin封装的原生HTML对应组件,结构和原实现完全一致,无需额外依赖,性能更优,原有CSS样式无需调整:

import com.vaadin.flow.component.html.Fieldset;
import com.vaadin.flow.component.html.Legend;

// 构造fieldset容器,等价于原CustomLayout根节点
Fieldset fieldset = new Fieldset();
fieldset.setSizeUndefined();

// 插入标题到legend节点
Legend legend = new Legend(title);
fieldset.add(legend);

// 插入内容面板
fieldset.add(panel);

方案2:沿用CustomLayout写法(最小迁移改动)

如果原有CustomLayout模板复杂度高,不想全量重构,可以使用Vaadin Flow提供的新版CustomLayout组件,仅需修改模板占位符属性即可:

import com.vaadin.flow.component.customlayout.CustomLayout;
import com.vaadin.flow.component.html.Label;

// 注意:占位符属性从原来的location改为slot
CustomLayout cl1 = new CustomLayout("<fieldset><legend slot='legend'></legend><div slot='content'></div></fieldset>");
cl1.setSizeUndefined();
cl1.add(new Label(title), "legend");
cl1.add(panel, "content");

注意:新版CustomLayout的模板占位符属性已从location调整为slot,必须修改对应属性才能正确匹配插入的组件

内容的提问来源于stack exchange,提问作者user1591192

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 17:54:03