我是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>
在定义模板文件时,您在WEB-INF
之前错过了/
。
<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:composition>