Facelets继承
Facelets inheritance
我想使用 Facelets 从基本模板继承,但我不知道该怎么做;
我在同一个文件夹中有两个文件:base.xhtml 和 login.xhtml 我希望 login.xhtml 继承自 base.xhtml,我应该包含任何库以进行简单继承吗?我想要的只是覆盖 login.xhtml 上的标题标签和 body 标签;
base.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:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title><ui:insert name="titre" /></title>
<link type="text/css" rel="stylesheet" href="resources/css/bootstrap.css"></link>
<link type="text/css" rel="stylesheet" href="resources/css/tether.min.css"></link>
<script type="text/javascript" src="resources/js/jquery.js"></script>
<script type="text/javascript" src="resources/js/tether.min.js"></script>
<script type="text/javascript" src="resources/js/bootstrap.js"></script>
<script type="text/javascript" src="resources/js/sortable.js"></script>
</h:head>
<h:body>
</h:body>
</html>
模板页面,即 template_name.xhtml
通常放在 WEB-INF
文件夹中,可能在您新创建的文件夹下,如下所示:
--WEB-INF
|--templates
|--template.xhtml
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 xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<ui:insert name="tabTitle">
Some default title
</ui:insert>
// normally you leave spaces for you to define external resources
<ui:insert name="css" />
<ui:insert name="js" />
</h:head>
<h:body>
<ui:insert name="body">
Default content
</ui:insrt>
</h:body>
</html>
然后,每当您想使用上方模板时:
some_page.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
template="/WEB-INF/templates/template.xhtml">
// the just override any <ui:insert /> tag you want by setting the
// name="" attribute to which ever you want to override
<ui:define name="body">
this will be the content that overrides your template "body", the rest will stay the same
</ui:define>
</ui:composition>
不需要其他任何东西的原因是因为 <ui:compsition
标签不会考虑其标签之外 的任何内容。
我想使用 Facelets 从基本模板继承,但我不知道该怎么做; 我在同一个文件夹中有两个文件:base.xhtml 和 login.xhtml 我希望 login.xhtml 继承自 base.xhtml,我应该包含任何库以进行简单继承吗?我想要的只是覆盖 login.xhtml 上的标题标签和 body 标签;
base.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:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title><ui:insert name="titre" /></title>
<link type="text/css" rel="stylesheet" href="resources/css/bootstrap.css"></link>
<link type="text/css" rel="stylesheet" href="resources/css/tether.min.css"></link>
<script type="text/javascript" src="resources/js/jquery.js"></script>
<script type="text/javascript" src="resources/js/tether.min.js"></script>
<script type="text/javascript" src="resources/js/bootstrap.js"></script>
<script type="text/javascript" src="resources/js/sortable.js"></script>
</h:head>
<h:body>
</h:body>
</html>
模板页面,即 template_name.xhtml
通常放在 WEB-INF
文件夹中,可能在您新创建的文件夹下,如下所示:
--WEB-INF
|--templates
|--template.xhtml
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 xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<ui:insert name="tabTitle">
Some default title
</ui:insert>
// normally you leave spaces for you to define external resources
<ui:insert name="css" />
<ui:insert name="js" />
</h:head>
<h:body>
<ui:insert name="body">
Default content
</ui:insrt>
</h:body>
</html>
然后,每当您想使用上方模板时:
some_page.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
template="/WEB-INF/templates/template.xhtml">
// the just override any <ui:insert /> tag you want by setting the
// name="" attribute to which ever you want to override
<ui:define name="body">
this will be the content that overrides your template "body", the rest will stay the same
</ui:define>
</ui:composition>
不需要其他任何东西的原因是因为 <ui:compsition
标签不会考虑其标签之外 的任何内容。