有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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) 个答案

  1. # 1 楼答案

    UI本身就是一个组件,它实现了HasComponents。因此,您可以简单地调用add(Component...)方法来用组件填充它