我是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>
答案 0 :(得分:0)
在定义模板文件时,/
之前错过了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>