私はJSFとfaceletsの初心者です。このチュートリアルに基づいて 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>