首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用手动示例代码在Vaadin流中编写“‘s”子类

使用手动示例代码在Vaadin流中编写“‘s”子类
EN

Stack Overflow用户
提问于 2018-11-12 22:43:38
回答 1查看 206关注 0票数 2

https://vaadin.com/docs/v10/flow/migration/3-general-differences.html手册的页面上,对于那些想要像我们在Vaadin 8中那样编写UI子类的人提供了这个示例代码,尽管在Vaadin流中不再需要。

(将原来的mydomain-dot更改为example.com以安抚堆栈溢出检查机器人)

代码语言:javascript
运行
复制
@WebServlet(urlPatterns = "/*", name = "myservlet", asyncSupported = true,
// Example on initialization parameter configuration
initParams = {
        @WebInitParam(name = "frontend.url.es6", value = "http://example.com/es6/"),
        @WebInitParam(name = "frontend.url.es5", value = "http://example.com/es5/") })
// The UI configuration is optional
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public class MyServlet extends VaadinServlet {
}

// this is not necessary anymore, but might help you get started with migration
public class MyUI extends UI {
    protected void init(VaadinRequest request) {
        // do initial steps here.
        // previously routing
    }
}   

在语法上,这要么是不正确的,要么是要写入两个单独的.java文件。

或者应该在MyServlet类中设置MyUI类,就像在Vaadin 8中默认的那样?如下所示:

代码语言:javascript
运行
复制
package com.raddkit;

import com.vaadin.flow.component.UI;
import com.vaadin.flow.server.VaadinRequest;
import com.vaadin.flow.server.VaadinServlet;
import com.vaadin.flow.server.VaadinServletConfiguration;

import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;

public class MyUI extends UI {
    protected void init ( VaadinRequest request ) {

    }

    @WebServlet ( urlPatterns = "/*", name = "myservlet", asyncSupported = true,
        // Example on initialization parameter configuration
        initParams = {
            @WebInitParam ( name = "frontend.url.es6", value = "http://example.com/es6/" ) ,
            @WebInitParam ( name = "frontend.url.es5", value = "http://example.com/es5/" ) } )
    // The UI configuration is optional
    @VaadinServletConfiguration ( ui = MyUI.class, productionMode = false )
    public class MyServlet extends VaadinServlet {
    }
}
EN

回答 1

Stack Overflow用户

发布于 2018-11-13 15:56:07

该示例将被写入两个独立的.java文件中。或者,您可以将servlet定义为包含在UI类中的公共静态内部类。在这种情况下,ui属性的@VaadinServletConfiguration默认为封闭UI。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53271168

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档