我如何使用ui:define和ui:在同一个ui:composition中插入?

时间:2016-11-10 21:29:12

标签: jsf

我有一个<?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> 位于模板中,我想在模板和合成本身中重复一个元素。

这是一个例子。

的template.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>

module.xhtml

chapter=4
curl -s "$url" | sed -n '/^CHAPTER '"$chapter"'\./,$p' | say

定义的内容徽标将在模板标题中显示正确 - 但它不会显示在合成主体中。我有没有办法在不诉诸复制HTML的情况下完成这项工作?

1 个答案:

答案 0 :(得分:0)

你可以像你这样使用你的module.xhtml中的ui:include

<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"> 
                    <ui:include src="logo.xhtml"/>
                </ui:define>

                <ui:define name ="content">                

                    <-- we also want to display the content-logo here--> 
                    <ui:include src="logo.xhtml"/> 
                    <div class = "foo">
                        My main content
                    </div>

                </ui:define>

</ui:composition>
相关问题