隨筆-112  評(píng)論-73  文章-0  trackbacks-0

          facelets 可以自定義組件,今天看了一下,果然好用。

          以前使用facelets只是定義一個(gè)界面的模板,并不沒(méi)有深入它的自定義組件方面的內(nèi)容,其實(shí)它的自定義組件也就是定義一個(gè)tag,然后在xhtml中引入這個(gè)tag,但這要比普通的JSP方式的tag方便多了。

          要想引用自定義的tag要在web.xml中加入下面代碼(前提是一定配置好其他的facelets內(nèi)容)

          <context-param>
          <param-name>facelets.LIBRARIES</param-name>
          <param-value>
          /WEB-INF/tld/xiangyun.taglib.xml
          </param-value>
          </context-param>

          xiangyun.taglib.xml文件的內(nèi)容如下:

          <?xml version="1.0"?>
          <!DOCTYPE facelet-taglib PUBLIC
          "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
          "

          <facelet-taglib>
          <namespace>http://xiangyun.cn/components</namespace>
          <tag>
          <tag-name>echo</tag-name>
          <source>component.jspx</source>
          </tag>
          </facelet-taglib>

          在這里引用了一個(gè)component.jspx文件,這個(gè)文件就是一個(gè)或一組想放在一塊當(dāng)做一個(gè)組件使用的內(nèi)容,和其他的jspx文件的寫(xiě)法一樣。內(nèi)容如下:


          <ui:composition xmlns:ui="
          <ice:selectInputDate id="inputDate" popupDateFormat="MM/dd/yyyy"
          value="#{inputDate}" renderAsPopup="true"
          styleClass="iceSelInpDateInput" onkeydown="ctlent(event);"
          rendered="true">
          </ice:selectInputDate>
          <h:outputText value="#{inputDate}"
          rendered="true" styleClass="printText">
          <f:convertDateTime dateStyle="long" type="date" timeZone="GMT+8"
          locale="cn" />
          </h:outputText>
          </ui:composition>

          只需要注意<ui:composition>標(biāo)簽和引入的命名空間就行,標(biāo)簽里面的內(nèi)容就看你要完成的功能了。在這里我使用了ICEfaces的日期組件,可以替換成JSF支技的任何東西。

          接下來(lái)就是要使用了。

          <html xmlns="<ui:composition template="/pages/layout/layout.jspx">
          <ui:define name="content">
          <h:form id="testForm">
          <ald:echo inputDate="#{testBean.date}"/>
          </h:form>
          </ui:define>
          </ui:composition>
          </html>

          這里需要引入命名空間,定義前綴為ald,

          <ald:echo>這個(gè)標(biāo)簽名同xiangyun.taglib.xml中聲明的要一致,inputDate是在定義組件component.jspx中聲明的#{inputDate},它可以接收EL表達(dá)式。

          這樣我們就可以把大的復(fù)雜的頁(yè)面,分成可以重用的組件了。

          有問(wèn)題可以和我聯(lián)系:wfn_libo@163.com

          也可以參考https://facelets.dev.java.net/nonav/docs/dev/docbook.html#gettingstarted-bean

          Technorati : ,

          posted on 2008-07-18 15:22 Libo 閱讀(2304) 評(píng)論(1)  編輯  收藏 所屬分類: JavaServer Faces

          評(píng)論:
          # re: Facelets組件 2008-07-18 15:59 | bangbang
          自定義組件才是facelets的精華啊。  回復(fù)  更多評(píng)論
            
          主站蜘蛛池模板: 万载县| 马公市| 海伦市| 德兴市| 张家口市| 黔东| 海晏县| 榆中县| 韶关市| 祁阳县| 堆龙德庆县| 吉木乃县| 石嘴山市| 施甸县| 老河口市| 霍林郭勒市| 突泉县| 潞西市| 如皋市| 桑日县| 漠河县| 会宁县| 通河县| 怀化市| 酉阳| 汶上县| 新竹县| 延寿县| 东阳市| 开化县| 梁山县| 樟树市| 漳州市| 博白县| 新乡市| 中牟县| 阜阳市| 阿拉善左旗| 邵武市| 迁西县| 哈密市|