【发布时间】:2016-11-10 21:29:12
【问题描述】:
我有一个位于模板中的ui:composition,我想在模板和合成本身中重复一个元素。
这是一个例子。
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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough">
<h:head>
<title>JSF 2.0 Hello World</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
</h:head>
<h:body>
<div class = "header">
<div class = "mylogo"></div>
HEADER
<!-- I want this content logo to be defined within module.xhtml-->
<ui:insert name = "content-logo"></ui:insert>
</div>
<div class = "content">
<ui:insert name = "content"></ui:insert>
</div>
<div class ="footer">
FOOTER
</div>
</h:body>
</html>
module.xhtml
<!DOCTYPE html>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:o="http://omnifaces.org/ui"
template="template.xhtml">
<!-- define the module content-logo here-->
<ui:define name ="content-logo">
<div class ="another-logo"> foo</div>
</ui:define>
<ui:define name ="content">
<-- we also want to display the content-logo here-->
<ui:insert name = "content-logo"/>
<div class = "foo">
My main content
</div>
</ui:define>
</ui:composition>
定义的 content-logo 将很好地显示在模板标题中 - 但它不会显示在组合正文中。有没有一种方法可以在不复制 HTML 的情况下完成这项工作?
【问题讨论】:
标签: jsf