在 V10 和 V8 应用程序之间的差异手册的页面上,有这个示例代码供那些想要像在 Vaadin 8 中那样编写子类的人使用,尽管在Vaadin FlowUI
中不再需要。
(将原来的 mydomain-dot-com 更改example.com
为安抚 Stack Overflow 审查机器人)
@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 {
}
}