在组合上使用新的xmlns.jcp.org命名空间会在java.util.concurrent.ConcurrentHashMap.putIfAbsent处导致java.lang.NullPointerException [英] Using new xmlns.jcp.org namespace on composites causes java.lang.NullPointerException at java.util.concurrent.ConcurrentHashMap.putIfAbsent

查看:347
本文介绍了在组合上使用新的xmlns.jcp.org命名空间会在java.util.concurrent.ConcurrentHashMap.putIfAbsent处导致java.lang.NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

在我的IDE的8.5 Composite Components一章中键入示例代码并在GlassFish4.0上运行该示例后,出现错误

After I typed the example code in the chapter 8.5 Composite Components in my IDE and run the example on GlassFish4.0, I got an error

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)

然后,我检查了本教程的较旧版本,发现有所不同.

Then I check the older version of this tutorial, I found a difference.

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

In the Java EE 7 version the email.xhtml code is like following:

<!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版本中

But in the Java EE 6 version

<!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版本后,错误消失了.区别在于名称空间.我不知道这是否是本教程的问题.有什么知道的吗?

After I changed the code to Java EE 6 version, the error is gone. The difference is the namespace. I don't know whether this is an issue of this tutorial. Is there any knows?

推荐答案

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

The way how the new xmlns.jcp.org XML namespaces are been handled is broken in the first Mojarra releases 2.2.0 and 2.2.1. It has been fixed in Mojarra 2.2.2 (note: ticket in the link describes different problem symptom, but under the covers, it's essentially the same cause). It's recommended to upgrade to at least Mojarra 2.2.2 (always pick the newest available, if possible). GlassFish 4.0 has 2.2.0 bundled. You can get the JAR from javaserverfaces.java.net. All you need to do is to replace javax.faces.jar file in GlassFish's /modules folder with the newer version.

Java EE 7教程本身很好.只是实现被打破了.顺便说一句,这种麻烦在GlassFish的第一个主要发行版中并不罕见(所有麻烦都无法按时完成).我建议使用Java EE 7,直到将GlassFish 4.0.1或4.1推出为止,以免日后出现意外情况.请注意,其他供应商(如Apache Tomcat和JBoss AS)也花一些时间来发布Java EE 7容器.他们还没有生产就绪版本.

The Java EE 7 tutorial itself is fine. It was just the implementation which was broken. This kind of trouble is by the way not unusual with the very first major GlassFish release (all hastle to get it ready on time). I recommend to wait with Java EE 7 until GlassFish 4.0.1 or 4.1 has been brought out to avoid future surprises. Note that other vendors like Apache Tomcat and JBoss AS take their time to release a Java EE 7 container; they don't have a production ready version yet.

这篇关于在组合上使用新的xmlns.jcp.org命名空间会在java.util.concurrent.ConcurrentHashMap.putIfAbsent处导致java.lang.NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆