【问题标题】:Using new xmlns.jcp.org namespace on composites causes java.lang.NullPointerException at java.util.concurrent.ConcurrentHashMap.putIfAbsent在组合上使用新的 xmlns.jcp.org 命名空间会导致 java.util.concurrent.ConcurrentHashMap.putIfAbsent 出现 java.lang.NullPointerException
【发布时间】:2013-08-28 11:50:14
【问题描述】:

我正在阅读来自http://docs.oracle.com/javaee/7/tutorial/doc/jsf-facelets005.htm#GIQZR 的 Java EE 7 教程

在我的 IDE 中键入第 8.5 章复合组件中的示例代码并在 GlassFish4.0 上运行示例后,出现错误

java.lang.NullPointerException
    at java.util.concurrent.ConcurrentHashMap.putIfAbsent(ConcurrentHashMap.java:1078)
    at com.sun.faces.util.Cache.get(Cache.java:116)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.getComponentMetadata(FaceletViewHandlingStrategy.java:237)
    at com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:951)
    at javax.faces.application.ApplicationWrapper.createComponent(ApplicationWrapper.java:648)

然后我检查了这个教程的旧版本,我发现了一个不同的地方。

在 Java EE 7 版本中,email.xhtml 代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:composite="http://xmlns.jcp.org/jsf/composite"
  xmlns:h="http://xmlns.jcp.org/jsf/html">

<h:head>
    <title>This content will not be displayed</title>
</h:head>
<h:body>
    <composite:interface>
        <composite:attribute name="value" required="false"/>
    </composite:interface>

    <composite:implementation>
        <h:outputLabel value="Email id: "></h:outputLabel>
        <h:inputText value="#{cc.attrs.value}"></h:inputText>
    </composite:implementation>
</h:body>
</html>

但在 Java EE 6 版本中

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:composite="http://java.sun.com/jsf/composite"
  xmlns:h="http://java.sun.com/jsf/html">

<h:head>
    <title>This content will not be displayed</title>
</h:head>
<h:body>
    <composite:interface>
        <composite:attribute name="value" required="false"/>
    </composite:interface>

    <composite:implementation>
        <h:outputLabel value="Email id: "></h:outputLabel>
        <h:inputText value="#{cc.attrs.value}"></h:inputText>
    </composite:implementation>
</h:body>
</html>

在我将代码更改为 Java EE 6 版本后,错误消失了。区别在于命名空间。我不知道这是否是本教程的问题。有知道的吗?

【问题讨论】:

    标签: jsf facelets xml-namespaces composite-component jsf-2.2


    【解决方案1】:

    处理新的xmlns.jcp.org XML 命名空间的方式在 Mojarra 的第一个版本 2.2.0 和 2.2.1 中被破坏了。它已在Mojarra 2.2.2 中修复(注意:链接中的票证描述了不同的问题症状,但在幕后,它本质上是相同的原因)。建议至少升级到 Mojarra 2.2.2(如果可能,请始终选择最新的可用版本)。 GlassFish 4.0 捆绑了 2.2.0。您可以从javaserverfaces.java.net 获取 JAR。您需要做的就是将 GlassFish 的 /modules 文件夹中的 javax.faces.jar 文件替换为较新的版本。

    Java EE 7 教程本身很好。只是实施被破坏了。顺便说一下,这种麻烦在 GlassFish 的第一个主要版本中并不罕见(所有这些都需要按时准备好)。我建议等到 GlassFish 4.0.1 或 4.1 推出后再使用 Java EE 7,以避免将来出现意外。请注意,Apache Tomcat 和 JBoss AS 等其他供应商会花时间发布 Java EE 7 容器。他们还没有生产就绪版本。

    【讨论】:

    • 我已经从链接下载了 jar Mojarra 2.2.2 并将其放入 /modules。但我仍然有同样的问题。我想我应该等待 GlassFish 4.1。无论如何,谢谢你的回复。
    • 我能够在未修改的 GF4 设置上重现您的问题。在我使用 Mojarra 2.2.2 升级后,您的用例开始为我工作。你清理了 GF4 的工作/缓存/部署文件夹了吗?你是如何管理服务器的?独立还是通过 IDE?请注意,如果我自己也没有确认/经历过这个问题,我通常不会发布答案。
    • 对第一个 cmets 感到抱歉。我忘记重命名 jar 文件以让 GlassFish 先加载它。现在可以了。谢谢
    猜你喜欢
    • 2014-10-26
    • 2014-12-26
    • 2016-06-25
    • 1970-01-01
    • 2012-05-31
    • 2018-08-19
    • 2013-09-02
    • 2021-02-26
    • 2014-05-09
    相关资源
    最近更新 更多