java - 使用手册的示例代码在 Vaadin Flow 中编写“UI”子类
问题描述
在 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 {
}
}
解决方案
该示例旨在写入两个单独的 .java 文件。或者,您可以将 servlet 定义为公共静态内部类,包含在 UI 类中。在这种情况下,ui
属性@VaadinServletConfiguration
默认为封闭的 UI。
推荐阅读
- reactjs - Gatsbyjs 图像与 Webp 并使用图片标签回退到 jpg 不起作用
- android - 是否可以通过 APNS 向通过 FCM 生成的设备令牌发送推送通知?
- java - Mysql存储过程在java中不起作用
- c# - asp.net core 中的身份验证和授权
- javascript - 如何防止用户在登录 Vuejs 后进入登录页面?
- pyspark - Can Spark jobs be scheduled through Airflow
- javascript - 如何比较对象数组中的键并使用javascript对其进行修改
- c# - 是什么使 C# 中的 SqlDataReader 类不可继承或不可实例化
- html - 在 html 表单中使用 ngForm 但出现错误
- flutter - Flutter InteractiveViewer 与 CustomPaint