Vaadin Flow web app中my`UI`子类的java设置内容
在Vaadin流中,不再需要编写UI
类的子类。然而,手册中关于Differences Between V10 and V8 Applications的那一页表明,我们可以自由地这样做
问题:流中的^{UI::setContent
方法
我们的UI::init
方法中的这一行代码在流中失败:
this.setContent( layout ); // <--- No method `setContent` found in Flow
➥ 我们如何设置在运行时在UI
子类中显示的内容
这是我的代码,其中的setContent
行失败
package com.acme;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.server.VaadinRequest;
import com.vaadin.flow.server.VaadinServlet;
import com.vaadin.flow.server.VaadinServletConfiguration;
import javax.servlet.annotation.WebServlet;
public class MyUI extends UI {
protected void init ( VaadinRequest request ) {
VerticalLayout layout = new VerticalLayout();
this.setContent( layout );
}
@WebServlet (
urlPatterns = "/*",
name = "myservlet",
asyncSupported = true
)
// The UI configuration is optional
@VaadinServletConfiguration (
ui = MyUI.class,
productionMode = false
)
public class MyServlet extends VaadinServlet {
}
}
# 1 楼答案
UI
本身就是一个组件,它实现了HasComponents
。因此,您可以简单地调用add(Component...)
方法来用组件填充它