在Vaadin Flow网络应用程序中设置我的UI子类的内容 [英] Setting content of my `UI` subclass in Vaadin Flow web app

查看:88
本文介绍了在Vaadin Flow网络应用程序中设置我的UI子类的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Vaadin Flow中,不再需要编写UI类的子类.但是,该手册的页面在 V10与V8应用程序 建议我们自由地这样做.

In Vaadin Flow, writing a subclass of UI class is no longer necessary. Yet the page of the manual on Differences Between V10 and V8 Applications suggests we are free to do so.

问题: UI Flow中的类没有UI::setContent方法.

The problem: The UI class in Flow has no UI::setContent method.

我们的UI::init方法中的这行常规代码在Flow中失败:

This usual line of code in our UI::init method fails in Flow:

this.setContent( layout );  // <--- No method `setContent` found in Flow

➥我们如何设置在运行时在UI子类中显示的内容?

➥ How do we set the content to be displayed within our UI subclass at runtime?

这是我的代码,其中setContent行失败.

Here is my code, with the line of setContent that fails.

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...)方法以将其填充组件即可.

The UI is a component itself and implements HasComponents. Hence, you can simply call add(Component...) method to fill it with components.

这篇关于在Vaadin Flow网络应用程序中设置我的UI子类的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆