【转载】 Facelets UI 标签参考

来源:互联网 发布:手风琴js 懒人之家 编辑:程序博客网 时间:2024/06/11 22:58

Source: 【转载】http://lalalabs.blog.163.com/blog/static/943252022009113693235/



ui:composition    
UI Composition标签是一个模板标签,它包装的内容被列在另一个Facelet中。任何UI Composition标签外的内容会被Facelets 视图处理器忽略。当另一个Facelets页面包含了具有UI Composition标签的页面时,任何 UI Composition标签内的内容会被列入。

ui:define

ui:define标签是一个模板标签,它定义插入到一个模板的命名内容。name属性的值必须与目标模板中的用于插入命名内容的 ui:insert标签的值相匹配 。

ui:insert

ui:insert标签是一个模板标签,它声明了一个被另一个Facelet定义的命名内容元素。 可以有效地利用它和ui:define标签在Facelets之间传值。

提示: 如果template属性指定了一个模板文件,包含了UI Composition标签的页面会显示相关联的模板页面的内容。如果UI Composition标签包含了ui:define标签,其内容会被插入到模板文件中相应的ui:insert标签位置。 模板页面可以使用一个无名的ui:insert标签,用于插入UI Composition标签内的所有内容。

ui:include
UI Include标签是一个用于Facelets的服务边包含标签。它只是包含由"src" 属性指定的文档作为当前页面的一部分。被包含的文档应该使用一个component或composition标签,削减不必要的标记,也可以只包含XHTML或被包括的XML的片断。

ui:param
ui:param标签用于页面之间的参数传送。


例子:
1.home.xhtml
<ui:composition ……  template="layout/template.xhtml">

    <ui:define name="body">

        <h1>Welcome to Seam!</h1>
        ……
    </ui:define>

</ui:composition>


2.template.xhtml
<f:view ……  contentType="text/html">
<html>
   <head>
     ……
   </head>
   <body>
      <ui:include src="menu.xhtml">
         <ui:param name="projectName" value="regist"/>
      </ui:include>
      <div class="body">
         ……
         <ui:insert name="body"/>
      </div>
      <div class="footer">
        ……
      </div>
   </body>
</html>
</f:view>

3.menu.xhtml
<rich:toolBar  …… >
    <rich:toolBarGroup>
        <h:outputText value="#{projectName}:"/>
        <s:link id="menuHomeId" view="/home.xhtml" value="Home" propagation="none"/>
    </rich:toolBarGroup>
    <rich:toolBarGroup location="right">
        <h:outputText id="menuWelcomeId" value="signed in as: #{credentials.username}" rendered="#

{identity.loggedIn}"/>
        <s:link id="menuLoginId" view="/login.xhtml" value="Login" rendered="#{not identity.loggedIn}"

propagation="none"/>
        <s:link id="menuLogoutId" view="/home.xhtml" action="#{identity.logout}" value="Logout" rendered="#

{identity.loggedIn}" propagation="none"/>
    </rich:toolBarGroup>
</rich:toolBar>

ui:repeat 
ui:repeat标签被用来迭代对象集,它由值绑定EL表达式暴露给JSF的。 目的是替换JSTL核心标签库的c:forEach标签。你也可以在Facelets中利用"jsfc" 功能使用这个标签。

例子:
<ul>
<ui:repeat value="#{myBean.products}" var="product">
  <li><h:outputText value="#{product.name}" /></li>
</ui:repeat>
</ul>

产生的HTML:
<ul>
  <li>Tennis Racquet</li>
  <li>Baseball Bat</li>
  <li>Hockey Stick</li>
</ul>

ui:remove 
ui:remove标签被用来指定Facelets视图处理器在编译时应该从页面删除的标签或内容块。这个标签没有属性。你可以在"jsfc"属性中使用这个标签指明应该从显示的页面中删除的特殊标签。

注意: Facelets编译处理比JSP编译处理快很多 ,在于它不会真正地产生Java字节码,并且当你第一次浏览你的页面时,在幕后进行编译。

例子:
This text will be displayed.
<ui:remove>
This text will be removed.
</ui:remove>
This text will be displayed.

产生的HTML:
This text will be displayed.
This text will be displayed.

ui:fragment 
ui:fragment标签插入一个新的UIComponent实例到JSF组件树。在这个标签外的任何组件或内容片断会被Facelets视图处理器纳入,在这个标签内的任何组件或内容片断会被增加到这个组件树,作为这个组件实例的一个孩子。

例子:
This text will be included.
<ui:fragment binding="#{myBackingBean.component}">
</ui:fragment>
  <div id="message">Hello World!/div>
This text will be included.

产生的HTML:
This text will be included.
  <div id="message">Hello World!/div>
This text will be included.

ui:component 
ui:component标签插入一个新的UIComponent实例到JSF组件树。在这个标签外的任何组件或内容片断会被Facelets视图处理器忽略,这个标签内的任何组件或内容片断会被增加到这个组件树,作为这个组件实例的一个孩子。

例子:
This text will be ignored.
<ui:component binding="#{myBean.component}">
  <div>Hello World!</div>
</ui:component>
This text will be ignored.

产生的HTML:
<div>Hello World!</div> 

ui:decorate 
ui:decorate标签是一个模板标签,它修饰来自另一个Facelet包含的内容。 在这个标签外的任何内容会被Facelets视图处理器显示。 在这个标签内的任何内容会被传递给相关联的模板作为参数或完全忽略。 你可以使用嵌套的ui:define标签传递命名内容给相关联的模板。详情见ui:insert标签。

模板提示:
包含decorate标签的页面的内容被用来填充关联的模板页面。如果decorate标签包含了ui:define 标签,这些标签的内容会被插入到模板中找到的相匹配的ui:insert的位置。你可以使用一个无名的ui:insert标签把所有composition标签的内容插入到模板页面内。

例子:
template.jsf

This text will be removed.
<ui:composition>
  <h2><ui:insert name="title" /></h2>
  <ui:insert name="body" />
</ui:composition>
This text will be removed.

decorate.jsf:
Text before will stay.<br />
<ui:decorate template="template.jsf">
<ui:define name="title">Our Products</ui:define>
  <ui:define name="body">
    <ul>
      <li>Apples</li>
      <li>Oranges</li>
      <li>Bananas</li>
    </ul>
  </ui:define>
</ui:decorate>
Text after will stay.


产生的HTML:
Text before will stay.<br />
<h2>Our Products</h2>
  <ul>
    <li>Apples</li>
    <li>Oranges</li>
    <li>Bananas</li>
  </ul>
Text after will stay.

ui:debug 
UI Debug标签允许你在测试你的JSF页面时,在你的浏览器中显示有关JSF组件树和域变量的有用信息。 hotkey属性指定了一个组合键 (CTRL + SHIFT + D ,默认值)用来显示弹出窗口包含的内容。通过设置rendered属性可以启用或禁用UI Debu标签。

例子:
<h:commandButton value="Continue Shopping" action="#{shoppingCartBean.saveCart}">
  <ui:debug />
</h:commandButton>

0 0
原创粉丝点击