我正在与特立尼达学习Java EE,但遇到了一些问题。 Trinidad 2.x示例使用JSPX,而旧的演示站点使用纯JSF(XHTML)。当我尝试在XHTML中使用Facelets编写测试页面时,我不断收到java.lang.stackoverflowerror。我不确定这是配置问题还是语法错误。
我正在使用Glassfish V3,MySQL 5.6,JSF 2.1(Apache MyFace),Apache Trinidad 2.0。我遵循本指南的大部分内容:http://jianmingli.com/wp/?p=3813
堆栈跟踪我省略了剩余的日志,因为它太长了
java.lang.StackOverflowError
at java.net.URLStreamHandler.equals(URLStreamHandler.java:331)
at java.net.URL.equals(URL.java:862)
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:995)
at com.sun.faces.util.ExpiringConcurrentCache.get(ExpiringConcurrentCache.java:95)
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>jsf2.myfaces2.trinidad2.one</display-name>
<!-- ================= JSF Settings ================= -->
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Faces Servlet Mappings -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<!-- resource loader servlet -->
<servlet>
<servlet-name>resources</servlet-name>
<servlet-class>org.apache.myfaces.trinidad.webapp.ResourceServlet</servlet-class>
</servlet>
<!-- Important: You must include this adf mapping even though you are not
using ADF features. Without this mapping, JSF navigation will fail! -->
<servlet-mapping>
<servlet-name>resources</servlet-name>
<url-pattern>/adf/*</url-pattern>
</servlet-mapping>
<!-- setting the project stage to be DEVELOPMENT -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- Use client-side state saving. In Trinidad, it is an optimized, token-based
mechanism that is almost always a better choice than the standard JSF server-side
state saving. -->
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
<!--param-value> server</param-value -->
</context-param>
<!-- ================= Trinidad Settings ================= -->
<context-param>
<param-name>org.apache.myfaces.trinidad.USE_APPLICATION_VIEW_CACHE</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.trinidad.CHANGE_PERSISTENCE</param-name>
<param-value>session</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
<param-value></param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.trinidad.ALTERNATE_VIEW_HANDLER</param-name>
<!-- TrinidadFaceletViewHander must be the alternate view handler if SessionChangeManager
is used -->
<param-value>org.apache.myfaces.trinidadinternal.facelets.TrinidadFaceletViewHandler</param-value>
</context-param>
<context-param>
<!--Unfortunately, Facelets provides no hook for plugging the PageResolver
into the logic handling "facelets.VIEW_MAPPINGS". You should leave "facelets.VIEW_MAPPINGS"
unset and use "org.apache.myfaces.trinidad.FACELETS_VIEW_MAPPINGS" instead. -->
<param-name>org.apache.myfaces.trinidad.FACELETS_VIEW_MAPPINGS</param-name>
<param-value>*.xhtml</param-value>
</context-param>
<filter>
<filter-name>trinidad</filter-name>
<filter-class>org.apache.myfaces.trinidad.webapp.TrinidadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>trinidad</filter-name>
<servlet-name>faces</servlet-name>
</filter-mapping>
</web-app>
的index.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="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:trh="http://myfaces.apache.org/trinidad/html"
xmlns:tr="http://myfaces.apache.org/trinidad">
<ui:composition template="" >
<tr:table value="#{userTable.userList}" var="row">
<tr:column>
<f:facet name="header">
<tr:outputText value="User Name" />
</f:facet>
<tr:outputText value="#{row.username}" />
</tr:column>
<tr:column>
<f:facet name="header">
<tr:outputText value="Password" />
</f:facet>
<tr:outputText value="#{row.password}" />
</tr:column>
</tr:table>
</ui:composition>
</html>
index.jspx 当我将“javax.faces.FACELETS_VIEW_MAPPINGS”配置为* .jspx并省略web.xml中特定于Trinidad Facelets的配置时,这是有效的
<?xml version="1.0" encoding="iso-8859-1"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:trh="http://myfaces.apache.org/trinidad/html"
xmlns:tr="http://myfaces.apache.org/trinidad">
<f:view>
<tr:document>
<tr:table value="#{userTable.userList}" var="row">
<tr:column>
<f:facet name="header">
<tr:outputText value="User Name" />
</f:facet>
<tr:outputText value="#{row.username}" />
</tr:column>
<tr:column>
<f:facet name="header">
<tr:outputText value="Password" />
</f:facet>
<tr:outputText value="#{row.password}" />
</tr:column>
</tr:table>
</tr:document>
</f:view>
</jsp:root>
答案 0 :(得分:1)
问题已修复,我认为 ui:composition template =“”是StackOverFlowError的原因。我删除 template =“”位后,就可以了。另外,我在Apache Trinidad的邮件存档中遇到了关于为Trinidad 2.0和Facelet配置web.xml的问题:
您不需要为Trinidad 2.0提供ALTERNATE_VIEW_HANDLER条目。
您收到错误,因为Trinidad尚未与之兼容 JSF 2.0中的部分状态保存。 由于在使用Facelets时默认启用部分状态保存, 你需要明确禁用它。 在web.xml中添加以下上下文参数:
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>
答案 1 :(得分:0)
当您在 Faceletes 中使用模板的相对路径时,Trinidad 似乎会导致 StackOverflowError
。在您的情况下,从 template=""
中删除无关的 ui:component
属性解决了该问题。就我而言,我实际上在视图中使用了模板,因此我无法删除该属性。相反,我可以通过使用模板视图的绝对路径来解决这个问题。
例如,具有以下视图结构:
/views/template.xhtml
/view/index.xhtml
在index.xhtml
中,提供到template.xhtml
的相对路径会导致StackOverflowError
:
<f:view
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:include src="template.xhtml" />
</f:view>
更改为 /views/template.xhtml
的绝对路径修复了 StackOverflowError
:
<f:view
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:include src="/views/template.xhtml" />
</f:view>