代码之家  ›  专栏  ›  技术社区  ›  Danny

尝试使用Jakarta EE 10和Jakarta Faces 4创建自定义标记时出错

  •  0
  • Danny  · 技术社区  · 2 年前

    在“the Definitive Guide to Jakarta Faces In Jakarta EE 10:Building Java Based Enterprise Web Applications”一书中,有一个使用自定义标记和 .xhtml 但当我尝试使用Wildfly 27运行此示例,Jakarta面对4时,它会抛出以下错误:

    Caused by: java.lang.RuntimeException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Cannot invoke "org.w3c.dom.Document.getDocumentElement()" because "document" is null
        at [email protected]//io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:257)
        at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:105)
        at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:87)
        ... 8 more
    Caused by: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Cannot invoke "org.w3c.dom.Document.getDocumentElement()" because "document" is null
        at [email protected]//com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:247)
        at [email protected]//io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:187)
        at [email protected]//io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:219)
        at [email protected]//io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:187)
        at [email protected]//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
        at [email protected]//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
        at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1430)
        at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1430)
        at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1430)
        at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1430)
        at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1430)
        at [email protected]//io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:255)
        ... 10 more
    Caused by: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Cannot invoke "org.w3c.dom.Document.getDocumentElement()" because "document" is null
        at [email protected]//com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:319)
        at [email protected]//com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:179)
        ... 21 more
    Caused by: java.lang.NullPointerException: Cannot invoke "org.w3c.dom.Document.getDocumentElement()" because "document" is null
        at [email protected]//com.sun.faces.config.processor.FaceletTaglibConfigProcessor.process(FaceletTaglibConfigProcessor.java:222)
        at [email protected]//com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:310)
        ... 22 more
    
    11:58:12,227 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([("deployment" => "jakartaee-hello-world.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"ROOT.war\".undertow-deployment" => "java.lang.RuntimeException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Cannot invoke \"org.w3c.dom.Document.getDocumentElement()\" because \"document\" is null
        Caused by: java.lang.RuntimeException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Cannot invoke \"org.w3c.dom.Document.getDocumentElement()\" because \"document\" is null
        Caused by: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Cannot invoke \"org.w3c.dom.Document.getDocumentElement()\" because \"document\" is null
        Caused by: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Cannot invoke \"org.w3c.dom.Document.getDocumentElement()\" because \"document\" is null
        Caused by: java.lang.NullPointerException: Cannot invoke \"org.w3c.dom.Document.getDocumentElement()\" because \"document\" is null"}}
    

    首先,我在中创建了文件apollo.taglib.xml WEB-INF 包含此内容的文件夹:

    <?xml version="1.0" encoding="UTF-8"?>
    <facelet-taglib xmlns:="https://jakarta.ee/xml/ns/jakartaee"
                    xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
                    https://jakarta.ee/xml/ns/jakartaee/web-facelettaglibrary_4_0.xsd"
                    version="4.0">
      <namespace>com.saukisoft.apollo.tags</namespace>
      <short-name>a</short-name>
      <tag>
        <description>Vertical box.</description>
        <tag-name>vbox</tag-name>
        <source>tags/vbox.xhtml</source>
        <attribute>
          <description>The space between items.</description>
          <name>gap</name>
          <required>false</required>
          <type>java.lang.String</type>
        </attribute>
      </tag>
      <tag>
        <description>Horizontal box.</description>
        <tag-name>hbox</tag-name>
        <source>tags/hbox.xhtml</source>
        <attribute>
          <description>The space between items.</description>
          <name>gap</name>
          <required>false</required>
          <type>java.lang.String</type>
        </attribute>
      </tag>
    </facelet-taglib>
    

    然后我在中创建了两个模板 WEB-INF/tags :

    hbox.xhtml

    <ui:composition xmlns:ui="jakarta.faces.facelets">
      <div class="hstack gap-3">
        <ui:insert/>
      </div>
    </ui:composition>
    

    vbox.xhtml

    <ui:composition xmlns:ui="jakarta.faces.facelets">
      <div class="vstack gap-3">
        <ui:insert/>
      </div>
    </ui:composition>
    

    最后,添加了 context-param 在里面 web.xml 描述新taglib.xml文件的文件:

    ...
      <context-param>
        <param-name>jakarta.faces.FACELETS_LIBRARIES</param-name>
        <param-value>/WEB-INF/apollo.taglib.xml</param-value>
      </context-param>
    ...
    

    启动Wildfly时,会引发以下错误:

    11:58:12,227 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([("deployment" => "jakartaee-hello-world.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"ROOT.war\".undertow-deployment" => "java.lang.RuntimeException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Cannot invoke \"org.w3c.dom.Document.getDocumentElement()\" because \"document\" is null
        Caused by: java.lang.RuntimeException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Cannot invoke \"org.w3c.dom.Document.getDocumentElement()\" because \"document\" is null
        Caused by: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Cannot invoke \"org.w3c.dom.Document.getDocumentElement()\" because \"document\" is null
        Caused by: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Cannot invoke \"org.w3c.dom.Document.getDocumentElement()\" because \"document\" is null
        Caused by: java.lang.NullPointerException: Cannot invoke \"org.w3c.dom.Document.getDocumentElement()\" because \"document\" is null"}}
    

    环境

    • Java 17
    • 野蝇27
    • 雅加达EE 10
    • 雅加达面临4
    0 回复  |  直到 2 年前
        1
  •  0
  •   Danny    2 年前

    阅读Jakarta Faces 4.0文档,在示例中他们没有使用 xmlns taglib.xml文件中的属性。因此,当我从根标记中删除这些属性时,它就开始工作了,战争工件也顺利部署。这很奇怪,但解决方案是删除所有 xmlns 的属性 facelet-taglib 根标记:

      <namespace>apollo.tags</namespace>
      <short-name>a</short-name>
      <tag>
        <description>Vertical box.</description>
        <tag-name>vbox</tag-name>
        <source>tags/vbox.xhtml</source>
        <attribute>
          <description>The space between items.</description>
          <name>gap</name>
          <required>false</required>
          <type>java.lang.String</type>
        </attribute>
      </tag>
      <tag>
        <description>Horizontal box.</description>
        <tag-name>hbox</tag-name>
        <source>tags/hbox.xhtml</source>
        <attribute>
          <description>The space between items.</description>
          <name>gap</name>
          <required>false</required>
          <type>java.lang.String</type>
        </attribute>
      </tag>
    </facelet-taglib>
    

    现在它开始运行了。