【发布时间】:2014-06-11 01:21:16
【问题描述】:
我是 Java 和 JSF 的新手,正在尝试使用 JSF 模板 <ui:include> 和 <ui:insert> 创建测试页面。结果,我在页面上只得到了<ui:insert> 块,但没有呈现<ui:include>。有人可以建议这里有什么问题吗?这是我的模板main_template.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 lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Title Here</title>
</h:head>
<h:body>
<div id="header">
<ui:include src="header.xhtml"/>
</div>
<div>
<div id="menu">
<ui:insert name="menu">Menu string</ui:insert>
</div>
<div id="content" >
<ui:insert name="content">Main Content</ui:insert>
</div>
</div>
</h:body>
</html>
这里是index.xhtml:
<ui:composition template="WEB-INF/templates/main_template.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<ui:define name="menu">
<h1>Menu will be here</h1>
</ui:define>
<ui:define name="content">
<h1>New content here</h1>
<p>Blah blah</p>
</ui:define>
</ui:composition>
..和header.xhtml:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h2>Header page</h2>
<p>Include page blah blah lorem ipsum</p>
</ui:composition>
【问题讨论】:
-
如果 header.xhtml 和 main_template.xhtml 存储在不同的文件夹中,则需要在
ui:include中设置正确的 header.xhtml 路径。如果它在同一个文件夹中,请尝试使用<ui:include src="/WEB-INF/templates/header.xhtml" />。