特立尼达与小面导致堆栈溢出



我正在与特立尼达一起学习Java EE,但遇到了一些问题。特立尼达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)

网络.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>

索引.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 中省略特立尼达 Facelet 特定配置时,这有效.xml

<?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>

问题已修复,我相信 ui:composition template=" 是 StackOverFlowError 的原因。 一旦我删除了模板="位,它就起作用了。 此外,我在Apache Trinidad的邮件存档中遇到了以下内容,涉及为Trinidad 2.0和Facelet配置web.xml:

您不需要有ALTERNATE_VIEW_HANDLER特立尼达 2.0 的条目。

您收到错误是因为特立尼达尚不兼容JSF 2.0 中的部分状态保存。由于在使用 Facelet 时默认启用部分状态保存,您需要显式禁用它。在 web.xml 中添加以下上下文参数:

<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>

链接到阿帕奇特立尼达邮件

当您在 Facelet 中使用模板的相对路径时,特立尼达似乎会导致StackOverflowError。在您的情况下,从ui:component中删除无关的template=""属性可以解决问题。就我而言,我实际上在我的视图中使用了模板,因此我无法删除该属性。相反,我能够通过使用模板视图的绝对路径来解决此问题。

例如,具有以下视图结构:

/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>

相关内容

  • 没有找到相关文章

最新更新