使用手册的示例代码在Vaadin Flow中编写“ UI”子类

时间:2018-11-12 22:43:39

标签: java web-applications view vaadin vaadin-flow

Differences Between V10 and V8 Applications的手册页上,此示例代码适用于希望编写UI子类的人,就像我们在Vaadin 8中所做的那样,尽管{{3 }}。

(将原始的mydomain-dot-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文件中。

还是应该像在Vaadin 8中默认那样在MyServlet类中设置MyUI类?像这样:

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

答案 0 :(得分:0)

该示例旨在被写入两个单独的.java文件中。或者,您可以将Servlet定义为包含在UI类中的公共 static 内部类。在这种情况下,SELECT p2.post_title, p2.post_name, p2.guid FROM wp_site.wp_posts p1 INNER JOIN wp_site.wp_term_relationships AS TR ON TR.object_id = p1.ID INNER JOIN wp_site.wp_postmeta AS PM ON pm.post_id = p1.ID INNER JOIN wp_site.wp_posts AS p2 ON p2.ID = PM.meta_value WHERE p1.post_type = 'nav_menu_item' AND TR.term_taxonomy_id = ( SELECT wp_site.wp_terms.term_id FROM wp_site.wp_terms WHERE wp_terms.slug = 'my-menu') AND wp_site.pm.meta_key = '_menu_item_object_id' ORDER BY p1.menu_order ASC; 的{​​{1}}属性默认为封闭的UI。