序言:我是一名高级Vaadin开发人员(我使用过6,7,现在我的所有项目都迁移到了Vaadin 8).
我开始研究Vaadin 10/Flow,但我发现自己处于一些热水中.
我实际上正在努力的是"项目"本身.我越深入,我越觉得这个框架正在转变为基于css/html的框架,这需要比java更多的css/html知识.我的意思是,如果你不完全知道css和html如何工作,你就不能再轻松地使用这个框架了.
问题是,我不知道我是否完全忽略了这一点,我正在失去一杯水,或者如果那真的是一个完全不同的框架.这是我要求你提出意见的地方,以及一些对抗.
我发现了一些非常好的东西,比如@Router和所有新的导航范例和新的Mobile First组件,但是在示例中我真的找不到一种快速的方法来构建一个漂亮的外观和感觉布局而无需使用css和html.
使用Vaadin 8轻松完成任务对我来说很难理解......就像模板一样:使用Vaadin 10 Designer真的很奇怪.
我希望我只是错过了这一点,你们中的一些人可以帮助我清除我的想法.
的AbsoluteLayout在Vaadin 8(框架)使布局内的窗口小部件面向像素的位置放置.虽然不是我选择的第一个布局,但AbsoluteLayout它适合从其他使用面向像素位置的布局的UI构建平台移植代码.
手册中的示例代码:
// A 400x250 pixels size layout
AbsoluteLayout layout = new AbsoluteLayout();
layout.setWidth("400px");
layout.setHeight("250px");
// A component with coordinates for its top-left corner
TextField text = new TextField("Somewhere someplace");
layout.addComponent(text, "left: 50px; top: 50px;");
Run Code Online (Sandbox Code Playgroud)
我可以看到传递的参数只是CSS编码.但我不是HTML/CSS向导,这就是我首先使用基于Java的Vaadin的原因.
从Vaadin 8(框架)迁移到Vaadin 10(Flow)的迁移指南在这个组件列表中表示,8从8中未包含,他们也不打算在将来添加它.但该页面确实提供了有关替换的说明:AbsoluteLayoutAbsoluteLayout
使用例如Div可以很容易地在V10中实现相同的效果
选择“ 纯Java Servlet”选项后,我使用“ 入门”页面创建了一个新的Vaadin 14应用程序。
该网页成功下载了.zip我解压缩的文件,并使用IntelliJ Ultimate Edition 2019.2。打开。我等了几分钟,Maven才开始做,下载并重新配置了项目。最后我去了Maven的面板内的IntelliJ,跑的Lifecycle项目clean和install。
我在控制台上收到以下错误消息。
[ERROR] Failed to execute goal com.vaadin:vaadin-maven-plugin:14.0.0:prepare-frontend (default) on project acme: Execution default of goal com.vaadin:vaadin-maven-plugin:14.0.0:prepare-frontend failed:
[ERROR]
[ERROR] ======================================================================================================
[ERROR] Failed to determine 'node' tool.
[ERROR] Please install it either:
[ERROR] - by following the https://nodejs.org/en/download/ guide to install it globally
[ERROR] - or by running the frontend-maven-plugin goal to install it in this project:
[ERROR] $ mvn com.github.eirslett:frontend-maven-plugin:1.7.6:install-node-and-npm -DnodeVersion="v10.16.0" …Run Code Online (Sandbox Code Playgroud) 如何将行索引列添加到网格中,该列不会按照用户对行进行排序?
该解决方案不得包括对任何聚合物模板的更改,而应在 java 中完成。
我想为我的 Vaadin 20 应用程序做自定义主题变体。为此,我将为可用的 Lumo CSS 变量提供自定义值,例如--lumo-base-color和--lumo-primary-color。问题是我找不到可用变量的广泛列表。
我的问题是:
有什么想法为什么在生产环境中发布新的 Vaadin / Spring-Boot 应用程序时,Vaadin 不会在前端目录中渲染自定义 css,尽管它在调试模式下会渲染?
该应用程序是为生产而构建的,如下所示:
mvn install -Pproduction
Run Code Online (Sandbox Code Playgroud)
然后运行生成的应用程序,如下所示:
java --enable-preview -jar target\app-1.0-SNAPSHOT.jar
Run Code Online (Sandbox Code Playgroud)
通过 JAR 文件方法运行时,CSS 未在浏览器中正确应用。其他一切都很好。
当应用程序运行时如下:
mvn spring-boot:run
Run Code Online (Sandbox Code Playgroud)
所有页面均正确呈现。CSS 已正确加载。
在LoginView类中,CSS的导入如下:
@CssImport(value = "./views/login/login-view.css", themeFor = "vaadin-login-overlay-wrapper")
Run Code Online (Sandbox Code Playgroud)
login-view.css 文件位于 [项目目录]\frontend\views\login-view.css
当运行 mvn spring-boot:run 时,CSS 文件被正确拾取,但是,当使用 JAR 方法运行时,则不然。我不确定这是否是设计使然,但我没有看到 css 文件存储在生成的 JAR 文件中的任何位置。
为了缓解这种情况,我尝试将前端文件放在 [project dir]\src\main\resources\META-INF\frontend 中,而不是默认位置 [project dir]\frontend 中,因为我在某处读到 CssImport 在 resources\ 内部查找通过 JAR 运行时的 META-INF\frontend 文件夹。当我将文件放在这个位置时,CSS 文件会合并到 JAR 中,并且可以从 http://localhost:8080/frontend/views/login/login-view.css 进行访问,但是可惜 LoginView 页面似乎仍然不存在渲染 CSS。
该应用程序最初是使用 Vaadin 应用程序构建器构建的。pom.xml 与默认的大致相同。我正在运行 Vaadin 19.0.7。提前致谢
我得到了一个简单的 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 22+
我正在尝试使用 LitRenderer 在 Vaadin 网格中显示一些动态 html。
以前可以使用现已弃用的 TemplateRenderer使用此 hack 来实现
var templateRenderer = TemplateRenderer.<Event>of("""
<div>
<ul inner-h-t-m-l="[[item.html]]">
</ul>
</div>
""").withProperty("html", item -> {
String listItems = "";
for (EventItem eventItem : item.getEventItems()) {
listItems += "<li>"+eventItem.getValue()+"</li>";
}
return listItems;
});
/*
Produces html like
<div>
<ul>
<li>Thing 1</li>
<li>Thing 3</li>
<li>Thing 845</li>
</ul>
</div>
*/
Run Code Online (Sandbox Code Playgroud)
这里重要的部分是设置包装元素的innerHTML。
有没有办法使用 LitRenderer 来做到这一点?我发现 Lit-Template 本身就有unsafeHTML 指令来实现这种目的。但我没有运气尝试让它或其他方法发挥作用。
谢谢
更新:2021.3.2 修复示例代码
我使用了Hello World Starters下载页面中的Plain Java starter 应用程序。
我将其 Maven POM 更新为最新版本的依赖项。因此 Vaadin 23.3.1、Java 19、jetty-maven-plugin 10.0.12 等等。POM 看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns = "http://maven.apache.org/POM/4.0.0"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>project-base</artifactId>
<name>Project base for Vaadin</name>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>
<vaadin.version>23.3.1</vaadin.version>
<drivers.downloader.phase>pre-integration-test</drivers.downloader.phase>
</properties>
<repositories>
<!-- The order of definitions matters. Explicitly defining central here to make sure it has the highest priority. -->
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>vaadin-prereleases</id> …Run Code Online (Sandbox Code Playgroud) vaadin-flow ×10
vaadin ×9
java ×2
spring-boot ×2
vaadin-grid ×2
vaadin10 ×2
vaadin14 ×2
css-position ×1
layout ×1
lit ×1
maven ×1
node.js ×1
npm ×1
vaadin-lumo ×1
vaadin22 ×1