facelets 标签参考1
关键字: facelets 标签参考1
</ui:composition>
这里以及这里后的内容将被忽略
?
例如 :
<ui:composition template="bird-template.xhtml">
<ui:define name="title">Input Name</ui:define>
<ui:define name="summary">
<h:panelGrid columns="2">
<h:outputText value="Bird Name"/>
<h:outputText value="#{bird.name}"/> 34 Facelets Essentials
<h:outputText value="Life expectancy"/>
<h:outputText value="#{bird.lifeExpectancy}"/>
</h:panelGrid>
</ui:define>
</ui:composition>
?
这样 composition 标签内的内容按 bird-template.xhtml 模板文件的定义显示 , 模板文件中中必须有 <ui:insert name="title"> 和 <ui:insert name="summary"> 的定义。
创建一个组合视图主要使用 ui:composition, ui:define 和 ui:insert 标签。
?
"http://www.w3.org/TR/xhtml1/DTD/ ?
xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"> 36 Facelets Essentials
<body>
<ui:composition>
<div style="border: 1px solid black; display:block">
<ui:insert name="header"/>
</div>
<div style="border: 1px solid black; display:block">
<ui:insert name="content"/>
</div>
</ui:composition>
</body>
</html>
?
?
Listing 1-11. decorate-example.xhtml
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<head>
<title>Decorate example</title>
</head>
<body>
<p>These are the birds in today's menu:</p>
<ui:decorate template="box-template.xhtml">
<ui:define name="header">
Happy Parrot
</ui:define>
<ui:define name="content">
How many parrots do you want?
<h:inputText value="3"/>
</ui:define>
</ui:decorate>
<br/>
<ui:decorate template="box-template.xhtml">
<ui:define name="header">
Mighty Eagle
</ui:define>
<ui:define name="content">
Eagles are not available now.
</ui:define>
</ui:decorate>
</body>
</html>
?
html 输出内容 :
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Decorate example</title>
</head>
<body>
<p>These are the birds in today's menu:</p>
<div style="border: 1px solid black; display:block">
Happy Parrot
</div>
<div style="border: 1px solid black; display:block">
How many parrots do you want?
<input id="_id6" name="_id6"
type="text" value="3" />
</div>
<br/>
<div style="border: 1px solid black; display:block">
Mighty Eagle
</div>
<div style="border: 1px solid black; display:block">
Eagles are not available now.
</div>
</body>
</html>
?
"http://www.w3.org/TR/xhtml1/DTD/ ?
xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets">
<body>
<h1>
<ui:insert name="title">
No title
</ui:insert>
</h1>
<div>
<ui:insert name="content">
No content is defined
</ui:insert>
</div>
</body>
</html>
我们需要一个客户端模板 , 如下:
Listing 1-14. insert-client.xhtml
<ui:composition template="insert-template.xhtml">
<ui:define name="title">
The Parrot Quest
</ui:define>
</ui:composition>
我们只定义了 title 的内容,所以 content 使用默认值。输出如下:
<h1>
The Parrot Quest
</h1>
<div>
No content is defined
</div>
name 属性是可选的,如果没有被指定,整个客户端模板将被插入。也没必须要客户端模板定义 define 。如下:
Listing 1-15. insert-template2.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD ?
HTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/ ?
xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets">
<body>
<div>
<h1>One story of Birds</h1>
<ui:insert/>
</div>
</body>
</html>
Listing 1-16. insert-client2.xhtml
<ui:composition template="insert-template2.xhtml">
One day I decided to start counting
the number of parrots in the world,
just to find that...
<br/>
<h:inputTextarea value="#{backingBean.story}"/>
</ui:composition>
输出如下:
<div>
<h1>One story of Birds</h1>
One day I decided to start counting
the number of parrots in the world,
just to find that...
<br />
<textarea name="_id3"></textarea>
</div>
?