在https://vaadin.com/docs/v10/flow/migration/3-general-differences.html手册的页面上,对于那些想要像我们在Vaadin 8中那样编写UI
子类的人提供了这个示例代码,尽管在Vaadin流中不再需要。
(将原来的mydomain-dot更改为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 {
}
}
发布于 2018-11-13 15:56:07
该示例将被写入两个独立的.java文件中。或者,您可以将servlet定义为包含在UI类中的公共静态内部类。在这种情况下,ui
属性的@VaadinServletConfiguration
默认为封闭UI。
https://stackoverflow.com/questions/53271168
复制相似问题