![](/img/trans.png)
[英]Using manual’s example code for writing a `UI` subclass in Vaadin Flow
[英]Setting content of my `UI` subclass in Vaadin Flow web app
在 Vaadin Flow 中,不再需要编写UI
类的子类。 然而,关于V10 和 V8 应用程序之间差异的手册页面表明我们可以自由地这样做。
问题:Flow 中的UI
类没有UI::setContent
方法。
我们UI::init
方法中的这行代码在 Flow 中失败了:
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 {
}
}
UI
本身就是一个组件并实现了HasComponents
。 因此,您可以简单地调用add(Component...)
方法来用组件填充它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.