使用 Vaadin 12 并FormLayout在输入字段左侧添加标签。
我想设置标签列的宽度。如何使用 Java API 来实现这一点?
我得到了一个简单的 StreamResource 示例,其中 SpringSecurityContext 在单击下载锚点时神秘消失。基本上,当单击下载锚点时,createInputStream会调用方法来创建下载文件,但是当执行此方法时,SecurityContext 为空。下面是重现该问题的简化示例。
public class HomeView extends VerticalLayout {
public HomeView() {
Anchor anchor = new Anchor();
anchor.add("DOWNLOAD");
anchor.setHref(new StreamResource("file", () -> createInputStream()));
add(anchor);
// SecurityContext returns correct value and is not null.
System.err.println(SecurityContextHolder.getContext());
System.err.println("Thread name in constructor : " + Thread.currentThread().getName());
}
private InputStream createInputStream() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
outputStream.write("text".getBytes());
} catch (IOException e) {
e.printStackTrace();
}
// SecurityContextHolder.getContext() returns null here. Why?
System.err.println(SecurityContextHolder.getContext());
System.err.println("Thread name in createInputStream() : " …Run Code Online (Sandbox Code Playgroud) 我试图将我的 Vaadin14 项目运行到生产环境中,但我的应用程序找不到任何 vaadin 流组件。我有一个默认的 application.properties 和 POM,并从这里下载它https://vaadin.com/start/latest。我已经试过了,
删除节点模块 mvn clean mvn clean install -Pproduction mvn clean package -Pproduction
我收到这个错误
Failed to find the following imports in the `node_modules` tree:
- @vaadin/flow-frontend/contextMenuConnector-es6.js
- @vaadin/flow-frontend/comboBoxConnector.js
- @vaadin/flow-frontend/gridConnector.js
- @vaadin/flow-frontend/contextMenuConnector.js
- @vaadin/flow-frontend/flow-component-renderer.js
- @vaadin/flow-frontend/gridConnector-es6.js
- @vaadin/flow-frontend/comboBoxConnector-es6.js
- @vaadin/flow-frontend/vaadin-grid-flow-selection-column.js
Run Code Online (Sandbox Code Playgroud)
如果构建失败,请检查是否安装了 npm 包。
修复构建删除node_modules目录以重置模块。此外,您可以运行npm install以修复node_modules树结构。
TIA
使用 Vaadin 14 当我尝试执行以下代码时遇到以下错误
UI current = UI.getCurrent();
Thread th = new Thread(() -> {
UI.setCurrent(current);
current.access(() -> {
//calling my service to save the data
current.push();
});
});
th.start();
Run Code Online (Sandbox Code Playgroud)
我遇到上述错误的情况非常罕见,但需要将其删除,如 UI 中所示。
我按照 Vaadin 教程(创建协作视图)来广播事件并注册它们。
Registration eventRegistration;
@Override
protected void onAttach(AttachEvent attachEvent) {
log.debug("In attach...");
UI ui = attachEvent.getUI();
eventRegistration= Broadcaster.register(
"eventName",
message -> ui.access(() -> {
log.debug("Request to refresh grid...");
presenter.refreshGrid();
ui.push();
}));
}
@Override
protected void onDetach(DetachEvent detachEvent) {
log.debug("In detach...");
if(eventRegistration != null) {
eventRegistration.remove();
eventRegistration = null;
}
}
Run Code Online (Sandbox Code Playgroud)
一切正常,除了刷新页面时,onDetach()不执行 中的逻辑。但是,刷新后,您将进入该onAttach()方法。因此,您实际上将注册几个“相同”的侦听器,而无需删除前一个侦听器,并且实际上获得了两倍的侦听器。例如onDetach(),仅当您转到另一个菜单项时才能访问该方法。
Vaadin 推荐的在刷新之前/期间删除这些侦听器的方法是什么?
我目前是一名崭露头角的 Java 开发人员,想要进入 Vaadin 开发,目前正在尝试为我的应用程序实现用户会话登录。我已阅读有关使用 VaadinServlet 执行此操作的内容: https: //vaadin.com/docs/v10/flow/advanced/tutorial-application-lifecycle.html。
在不断地挖掘 API 文档和示例代码之后,我仍然无法理解如何为登录到我的平台的特定用户实现用户会话。据我了解,我可以使用下面实现的内容来初始化我的用户会话。
然而,我的应用程序目标略有不同:
[使用案例]
1.用户使用其特定凭据登录。
2.重定向到安全页面(这将创建一个存储用户用户名的用户会话并检索令牌?)
3.2-3 分钟不活动后,用户将被迫退出安全页面并且会话关闭?
@WebServlet(urlPatterns = "/*", name = "VaadinFlowServlet", asyncSupported = true)
@VaadinServletConfiguration(heartbeatInterval = 5, productionMode = false)
public class LoginServlet extends VaadinServlet implements SessionInitListener, SessionDestroyListener {
private static final Logger LOGGER = LoggerFactory.getLogger(LoginServlet.class);
// <Method> ::servletInitialized():: -> handles most of the servlet customization. (write my servlet customization under this function.
// ::getService():: -> returns a VaadinServletService type?
// ::addSessionInitListener(this):: -> An event listener …Run Code Online (Sandbox Code Playgroud) 我真的很困惑 Vaadin 的 Tabs/Tab 组件:
我创建了一个包含几个选项卡的页面,本质上是这样的:
Tabs tabs = new Tabs();
Tab tab1 = new Tab("Label 1");
tab1.add(<some components (labels and entry fields) here>);
tabs.add(tab1);
Tab tab2 = new Tab("Label 2");
tab2.add(<some components (labels and entry fields) here>);
tabs.add(tab2);
Tab tab3 = new Tab("Label 3");
tab3.add(<some components (labels and entry fields) here>);
tabs.add(tab3);
mainPage.add(tabs)
Run Code Online (Sandbox Code Playgroud)
我期望得到的渲染与此类似(当然以某些样式为模):
___________ ___________ ___________
/ Label 1 \/ *Label 2* \/ Label 3 \
+----------------------------------------------------+
| Content of Tab 2 visible |
| |
| (the …Run Code Online (Sandbox Code Playgroud) 我正在使用 Vaadin 20 Flow (Java),并且想要为我的 Web 应用程序分配图标/图像(.ico或)。.png该图标应显示在页面标题旁边,并应在页面添加书签时用作图标。
我知道可以通过实现界面PageConfigurator来分配这些图标。然而,这个功能接口现在已被弃用。有谁知道如何在新的 Vaadin 版本中实现这样的图标?
例如,在 Vaadin 8 中,您只需执行以下操作即可按屏幕上显示的顺序获取列的列表。
String columnOrderPreference = ((List<Grid.Column>)grid.getColumns()).stream()
.map(Grid.Column::getId)
.collect(Collectors.joining(VALUE_SEPARATOR));
Run Code Online (Sandbox Code Playgroud)
这特别方便,因为您可以保存该字符串,然后调用:
grid.setColumnOrder(columnOrderPreference.split(VALUE_SEPARATOR));
Run Code Online (Sandbox Code Playgroud)
在 Vaadin 14 中(忽略getId()现在应该使用的getKey()),这不再可能,因为getColumns()列表现在总是按照它们添加的顺序而不是它们的排序顺序返回。您仍然可以调用setColumnOrder(...)(使用不同的参数 - list of grid.getColumnByKey(columnKey)),但我无法弄清楚如何按照显示的顺序获取列列表。
这对于尝试保存用户返回同一页面(使用网格)时设置/更改的列顺序特别有用。
有没有办法检测该文件已添加到上传组件?有一个文件删除来检测文件是否被删除,我们可以以某种方式检测是否添加了文件吗?
简化场景:添加文件时显示简单的通知。