1

我正在与 Trinidad 一起学习 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

Stack Trace我省略了日志的其余部分,因为它太长了

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>

索引.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>
4

2 回答 2

0

问题已解决,我相信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>

链接到 Apache Trinidad 邮件帖子

于 2012-12-19T22:46:43.037 回答
0

StackOverflowError当您在 Faceletes 中使用模板的相对路径时,Trinidad 似乎会导致 a 。在您的情况下,从解决问题中删除无关template=""属性ui:component。就我而言,我实际上是在我的视图中使用模板,所以我无法删除该属性。相反,我能够通过使用模板视图的绝对路径来解决这个问题。

例如,使用以下视图结构:

/views/template.xhtml
/view/index.xhtml

index.xhtml中,提供template.xhtml导致 a的相对路径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>
于 2021-02-26T14:54:11.350 回答