代码之家  ›  专栏  ›  技术社区  ›  Basil Bourque

使用手册示例代码在Vaadin流中编写'UI'子类

  •  2
  • Basil Bourque  · 技术社区  · 7 年前

    在手册的第页 Differences Between V10 and V8 Applications ,这里有一个示例代码,供那些想编写 UI Vaadin Flow .

    (将原始mydomain.com更改为 example.com

    @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中默认做的那样?这样地:

    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 {
        }
    }
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Javier user3138333    7 年前

    静止的 内部类,包含在UI类中。在这种情况下 ui @VaadinServletConfiguration