为什么嵌入式vaadin 14组件没有显示在XHTML页面上?

我正在使用Vaadin 14.2,facelets和wildfly 18开发一个演示项目。 使用在pnpm中启用的pom.xml

我试图按照下面Vaadin网站上的文档中所述,将我的Vaadin视图之一嵌入到facelets页面中。

为什么嵌入式组件未显示在facelets页面上?

我尝试了调试和生产模式。

导航到JSF页面时,调试模式下的错误如下:

ERROR [dev-webpack] (webpack) ERROR in ../target/frontend/generated-flow-imports.js
ERROR [dev-webpack] (webpack) Module not found: Error: Can't resolve '@vaadin/flow-frontend/' in 'C:\Development\workspace\soft\fering-web\target\frontend'
ERROR [dev-webpack] (webpack)  @ ../target/frontend/generated-flow-imports.js 82:0-32

导航到facelets页面时,生产模式错误如下:

14:53:33,277 ERROR [com.vaadin.flow.server.frontend.FrontendUtils] (default task-4) Cannot get the 'stats.json' from the classpath 'Meta-INF/VAADIN/config/stats.json'
14:53:33,282 ERROR [com.vaadin.flow.server.DefaultErrorHandler] (default task-4) : com.vaadin.flow.server.BootstrapException: Unable to read webpack stats file.
Caused by: java.io.IOException: The stats file from webpack (stats.json) was not found.
The application is running in production mode.Verify that build-frontend task has executed successfully and that stats.json is on the classpath.Or switch application to development mode.
    at com.vaadin.flow.server.BootstrapHandler$BootstrapPageBuilder.appendNpmBundle(BootstrapHandler.java:923)
    at com.vaadin.flow.server.BootstrapHandler$BootstrapPageBuilder.setupFrameworklibraries(BootstrapHandler.java:889)
    ... 59 more

14:53:33,287 ERROR [io.undertow.request] (default task-4) UT005023: Exception handling request to /fering/vaadin/web-component/web-component-bootstrap.js: javax.servlet.ServletException: com.vaadin.flow.server.ServiceException: com.vaadin.flow.server.BootstrapException: Unable to read webpack stats file.
    at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:249)
    at com.vaadin.cdi.CdiVaadinServlet.service(CdiVaadinServlet.java:67)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
    at io.opentracing.contrib.jaxrs2.server.SpanFinishingFilter.doFilter(SpanFinishingFilter.java:52)

Facelets xhtml页面

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:fn="http://java.sun.com/jsp/jstl/functions"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<f:view contentType="text/html;charset=utf-8"/>
<ui:include src="/include/queryHeader.xhtml"/>
<h:head>
    <h:outputScript name="jquery/jquery.js" library="primefaces"/>
    <script type="text/javascript" src="vaadin/VAADIN/build/webcomponentsjs/webcomponents-loader.js"  ></script>
    <script type="module" src="vaadin/web-component/first-view.js"></script>
    <style type="text/css">
        first-view {
            width: 100%;
        }
        body {
            margin: 8px;
            width: auto;
            height: auto;
        }
    </style>
</h:head>

<h:body>
    <hr/>
    <first-view></first-view>

</h:body>

</html>

Vaadin嵌入式组件

@Tag("first-view")
@PreserveonRefresh
public class FirstViewExporter  extends WebComponentExporter<FirstView> {
    public FirstViewExporter() {
        super("first-view");
    }


    @Override
    protected void configureInstance(WebComponent<FirstView> webComponent,FirstView firstView) {

    }
}

pom.xml生产资料

<profiles>
        <profile>
            <id>production</id>
            <properties>
                <vaadin.productionmode>true</vaadin.productionmode>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>com.vaadin</groupId>
                    <artifactId>flow-server-production-mode</artifactId>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.vaadin</groupId>
                        <artifactId>vaadin-maven-plugin</artifactId>
                        <version>${vaadin.version}</version>
                        <configuration>
                            <pnpmEnable>true</pnpmEnable>
                        </configuration>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>prepare-frontend</goal>
                                    <goal>build-frontend</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
iCMS 回答:为什么嵌入式vaadin 14组件没有显示在XHTML页面上?

关于生产模式:请确保META-INF/VAADIN/config/stats.json资源在您的EAR / WAR / JAR中。它应该是由build-frontend目标的Vaadin Maven插件制作的-请从Maven stdout验证目标是否已运行。这里还有一些信息:https://vaadin.com/forum/thread/17763152/vaadin-14-npm-mode-production-profile; Vaadin可能也无法在瘦的EAR中发现类路径文件。

此特定配置也可能存在问题。在这种情况下,无论是在论坛上还是在https://github.com/vaadin/flow/issues

关于开发模式:Vaadin 14.2不再需要target\frontend文件夹。可能是您从Vaadin 14.1迁移了,但是javascript文件尚未更新。请尝试清理Vaadin文件:即删除node_modulespnpm-lock.yamlpackage.jsonpnpmfile.jswebpack.generated.js,然后再次尝试开发模式。>

反馈您的回复:

我已经附上了一个截图,其中包含项目结构师以及web.xml

的更多详细信息

从标准输出中,我看到build-frontend目标已经执行。

从下面的屏幕快照中可以看到,stats.json不在vaadin maven plugin目录中都不由META_INF生成。 enter image description here

本文链接:https://www.f2er.com/2196255.html

大家都在问