【问题标题】:JSF <ui:composition> is not working on destination pageJSF <ui:composition> 在目标页面上不起作用
【发布时间】:2011-08-17 03:00:28
【问题描述】:

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

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

表达式.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。

【问题讨论】:

  • 当它们是模板的一部分时,为什么在 expression.xhtml 页面中有 html 标签?您在 startPage.xhtml 中没有它们
  • 我在尝试不同的组合。最初我没有 标签。比我虽然可能会解决,但是..没用。
  • 你试过用
  • 哦不,我没试过。我现在就试试。
  • 啊!我使用的是 Richfaces 3.3.3,所以

标签: jsf navigation richfaces


【解决方案1】:
<jsp:forward page="startPage.jsf" />

您的index.jsp 表明FacesServletweb.xml 中映射到&lt;url-pattern&gt;*.jsf

然而,

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

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

您需要修复链接以匹配web.xmlFacesServlet&lt;url-pattern&gt;

<a href="#{request.contextPath}/expression/expression.jsf" style="font-size:20px;"> Expression Subsystem</a>

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

或者,您也可以将FacesServlet&lt;url-pattern&gt; 更改为*.xhtml。这样你就可以完全摆脱丑陋的index.jsp 并将你的&lt;welcome-file&gt; 设置为startPage.xhtml 并始终使用以.xhtml 结尾的URL/链接。

【讨论】:

  • 我怀疑这是问题所在,但是当我尝试它时,我制作了一种 .jfs 并且它没有用。然后我在SO上发布了问题。非常感谢。最终,我将更改 web.xml 以摆脱我的 idex.jsp。
猜你喜欢
  • 2015-05-16
  • 1970-01-01
  • 2012-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-31
  • 2017-08-13
  • 1970-01-01
相关资源
最近更新 更多