JSFне работает на странице назначения - PullRequest
2 голосов
/ 17 августа 2011

Я делаю простое JSF-приложение, которое использует шаблоны. Это очень простой материал, но на поиски решения уходит много времени.Проблема в том, что у меня есть index.jsp, который просто перенаправляет запрос в startPage.xhtml.startPage.xhtml использует main.xhtml для шаблонов.Пока здесь все в порядке.Но есть якорная ссылка startPage.xhtml, которая ведет элемент управления к expression / expression.html.Когда я нажимаю на эту ссылку, браузер не отображает мой верхний и нижний колонтитулы (часть шаблона main.xhtml).IE рассматривает expression / 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>

Есть предложения?

ПРИМЕЧАНИЕ. Все ссылки на странице являются статическими, поэтому я не использую управляемый компонент.

1 Ответ

2 голосов
/ 17 августа 2011
<jsp:forward page="startPage.jsf" />

Ваш index.jsp предполагает, что FacesServlet в web.xml отображается на <url-pattern> из *.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, он не знает, что с ним делать, поэтому просит загрузить его.

Вам необходимо исправить ссылку, чтобы она соответствовала <url-pattern> FacesServletв web.xml.

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

(обратите внимание, что я также упростил поиск по контекстному пути)

В качестве альтернативы, вы также можете просто изменить <url-pattern> изFacesServlet до *.xhtml.Таким образом, вы можете полностью избавиться от уродливого index.jsp, установить для <welcome-file> значение startPage.xhtml и постоянно использовать URL-адреса / ссылки, заканчивающиеся на .xhtml.

...