我正在阅读来自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 版本后,错误消失了。区别在于命名空间。我不知道这是否是本教程的问题。有知道的吗?