JSF facelets ui:include不起作用

时间:2015-10-26 07:34:04

标签: jsf facelets uiinclude

我是JSF和facelets的新手。我正在尝试基于this tutorial创建facelets模板。 common.xhtml不会在header/content/footer.xhtml中显示任何文字。我已经在stackoverflow上阅读了几个与此主题相关的帖子,并根据这些帖子尝试了几个不同的exp,但它们都不起作用。 localhost:8080/AppName/templates/common.xhtml始终是空白页面,但localhost:8080/AppName/templates/header.xhtml正确呈现。

感谢任何帮助。 我在这里想念的是什么?

header.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!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">
  <body> 
    <ui:composition>
    <h1>Default Header</h1>
    </ui:composition> 
  </body>
</html>

footer.xhtml和content.xhtml类似,因此在此处省略。

common.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!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">
<h:head></h:head>
<h:body>
    <div id="header">
        <ui:insert name="header">
            <ui:include src="/templates/header.xhtml" ></ui:include>

我尝试过以下几点 header.xhtml,templates / header.xhtml,./ header.xhtml,#{request.contextPath} /templates/header.xhtml 但是common.xhtml仍显示空白页面

     </ui:insert>
        <br></br>
    </div>
    <div id="content">
        <ui:insert name="content">
            <ui:include src="/templates/content.xhtml" ></ui:include>
        </ui:insert>
        <br></br>
    </div>
    <div id="footer">
        <ui:insert name="footer">
            <ui:include src="/templates/footer.xhtml" ></ui:include>
        </ui:insert>
        <br></br>
    </div>
</h:body>
</html>

项目文件结构:

WebContent
|->META-INF
|->WEB-INF
|->templates
         |-> common.xhtml
         |-> footer.xhtml
         |-> header.xhtml
         |-> content.xhtml

的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" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
         http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
         id="WebApp_ID"
         version="3.0">

  <display-name>MathTrainerJSFDemo</display-name>
  <welcome-file-list>
    <welcome-file>pages/common.xhtml</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>
  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
  </context-param>
  <listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
  </listener>
</web-app>

0 个答案:

没有答案