JSF <ui:composition>无法在目标页面上工作</ui:composition>

时间:2011-08-17 03:00:28

标签: jsf navigation richfaces

我正在制作一个简单的JSF应用程序,它使用模板这是非常基本的东西,但花了很多时间来找到修复。 问题是,我有index.jsp,它只是将请求转发给startPage.xhtml。 startPage.xhtml使用main.xhtml进行模板化。到这里一切都还好。但是有一个startPage.xhtml的锚链接,它将控件引导到表达式/ expression.html。当我点击该链接时,浏览器不会呈现我的页眉和页脚(main.xhtml模板的一部分)。 IE将表达式/ expression.xhtml视为一个文件,并使用打开/保存对话框打开它。

的index.jsp

<html>
 <body>
  <jsp:forward page="startPage.jsf" />
 </body>
</html>

main.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:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:a4j="http://richfaces.org/a4j"
        xmlns:rich="http://richfaces.org/rich"
        xmlns:c="http://java.sun.com/jstl/core">
    <head>
    <meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8" />
    <meta http-equiv="pragma" content="no-cache" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="expires" content="0" />

<title>X</title>
<link
    href="css/styles.css"
    rel="stylesheet" type="text/css" />

    <style>
        .rich-table-headercell {
            text-align: left;
        }

        .rich-table-cell {
            vertical-align: top;
        }
    </style>
</head>
<body
    style="bgcolor: #FFFFFF; margin-left: 0; margin-right: 0; margin-top: 0; margin-bottom: 20;">
    <!-- Start Header -->
    <h:form id="mainForm">

        <ui:include src="../includes/header.xhtml"/>

        <table width="100%" cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td nowrap="nowrap">
                    <table style="background-repeat: no-repeat; background-color: #E9ECEF; " width="100%" height="20px">
                        <tr>
                            <td nowrap="nowrap"><img
                                src="images/spacer.gif"
                                width="18" height="1" border="0" alt="" />
                            </td>
                            <td class="globalNavGrey" align="right" nowrap="nowrap">
                                <h:outputText value="Help" /> <rich:spacer width="10" />                                
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </h:form>
    <!-- main content area -->

    <table align="left">
        <tr>
            <td><img
                src="images/spacer.gif"
                width="5" height="1" border="0" alt="" />
            </td>
            <td style="vertical-align: top;">
                <!-- Body starts -->
                <ui:insert name="body">
                </ui:insert>
                <!-- Body ends -->
            </td>
        </tr>
    </table>
    </body>
</html>

startPage.xhtml

<?xml version="1.0" encoding="windows-1252"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.w3.org/1999/xhtml http://www.w3.org/2002/08/xhtml/xhtml1-transitional.xsd"
    template="/includes/main.xhtml">
<style>
    .cellBackground {
        background-color:yellow;
    }
</style>
    <ui:param name="subTitle" value="Understanding Disease Informatics System" />
    <ui:define name="body">
        <div
            style="margin-left: 30px; top: 120px; width: 800px; margin-bottom: 50px;"
            class="mainscreen">
            <br/> <b><font size="+1" color="003366">
X </font> </b><br/> <br/> This page is the entry point for X 
            developers development is organized into these subsystems:

            <p></p>
        <center>
            <table border="1" cellpadding="15" cellspacing="25">
                <tr>
                  <td class="cellBackground" title="Enabled" >
                    <a href="${facesContext.externalContext.requestContextPath}/expression/expression.xhtml" style="font-size:20px;"> Expression Subsystem</a>
                  </td>
                  <td title="Disable" style="font-size:20px;" >Pathways</td>                  
                </tr>                               
            </table>
        </center>
            <hr></hr>
            <font size="+1">
                <a href="contact">Contacts</a>
                <hr></hr>
            </font>
        </div>
    </ui:define>
</ui:composition>

expression.xhtml

<?xml version="1.0" encoding="windows-1252"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.w3.org/1999/xhtml http://www.w3.org/2002/08/xhtml/xhtml1-transitional.xsd">

<ui:composition template="main.xhtml">
<ui:param name="subTitle" value="Expression Data" />
    <ui:define name="body">
        Expression page!
    </ui:define>

</ui:composition>
</html>

有什么建议吗?

注意:由于页面上的所有链接都是静态的,因此我没有使用任何托管bean。

1 个答案:

答案 0 :(得分:2)

<jsp:forward page="startPage.jsf" />

您的index.jsp建议FacesServlet位于web.xml <url-pattern> *.jsf上。{/ 1}

然而,

<a href="${facesContext.externalContext.requestContextPath}/expression/expression.xhtml" style="font-size:20px;"> Expression Subsystem</a>

您的startPage.xhtmlexpression.xhtml而非expression.jsf的链接。 IE正在检索原始和未解析的JSF源代码而不是其生成的HTML。每当IE检索application/xhtml+xml文件时,它都不知道如何处理它,所以它要求下载它。

您需要修改链接以匹配<url-pattern>FacesServlet的{​​{1}}。

web.xml

(请注意,我还简化了上下文路径检索)

或者,您也可以将<a href="#{request.contextPath}/expression/expression.jsf" style="font-size:20px;"> Expression Subsystem</a> 的{​​{1}}更改为<url-pattern>。通过这种方式,您可以完全摆脱丑陋的FacesServlet并将*.xhtml设置为index.jsp,并始终使用以<welcome-file>结尾的网址/链接。