Tapestry

          記錄學習Tapestry專用布格格。很多文章都轉載網絡。

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            20 隨筆 :: 0 文章 :: 4 評論 :: 0 Trackbacks
          介紹:Tapestry框架底層使用了Hivemind這個小巧的IOC容器,很多功能都有相應的配置文件。
          這些配置文件主要包括:service-point(服務點), implementation(服務實現),configuration-point(配置點)和contribution(配置實現)三個關鍵概念。
          其中,服務點定義了服務的接口與默認實現,implementation可以覆蓋服務點的默認實現,服務點ID和配置點ID在一個模塊中必須唯一。


          擴展Tapestry4.0不需要修改tapestry-4.0.jar文件。

          實例1:結合一個實例來說明可能更容易理解,比如tapestry- 4.0.jar/META-INF/tapestry.form.validator.xml,其中定義了一個配置點Validators, tapestry使用的校驗器都在其中,如果想增加校驗器,則可以在/WEB-INF/hivemodule.xml中增加:
          <contribution configuration-id="tapestry.form.validator.Validators">
          ?? ??? ?<validator name="required2" class="com.mycom.tapestry.validator.Required2"/>?? ???
          ? ?? ?</contribution>

          在page中就可以引用增加的校驗器
          <component id="password" type="TextField">
          ?? ??? ?<binding name="value" value="password"/>
          ??????? <binding name="hidden" value="true"/>
          ??????? <binding name="displayName" value="message:password"/>
          ??????? <binding name="validators" value="validators:required2=login_3"/>
          ??? </component>

          注意:以上兩塊代碼中的粗體部分必須相同。

          實例2:擴展服務的實例,向tapestry中增加初始化任務。
          <service-point id="MyApplicationInitializer"
          ??????? interface="org.apache.tapestry.services.ApplicationInitializer"
          ??????? visibility="private">?????? ?
          ?? ??? ?<create-instance class="com.fitechlabs.xtrade.web.MyApplicationInitializer"/>
          ??? </service-point>

          ??? <!-- Hook it into the overall application initialization. -->?? ?
          ??? <contribution configuration-id="tapestry.init.ApplicationInitializers">
          ??????? <command id="my-init" object="service:MyApplicationInitializer"/>
          ??? </contribution>
          ? tapestry啟動時會自動執行MyApplicationInitializer的初始化任務。

          初始化類只需要實現接口ApplicationInitializer即可。
          public final class MyApplicationInitializer implements
          ?? ??? ?ApplicationInitializer {

          ?? ?public void initialize(HttpServlet servlet) {
          ?? ??? ?ServletContext context = servlet.getServletContext();
          ?? ??? ?String contextpath = null;
          ?? ??? ?try {
          ?? ??? ??? ?contextpath = context.getResource("/").getPath();

          ?? ??? ?} catch (MalformedURLException e) {
          ?? ??? ??? ?e.printStackTrace();
          ?? ??? ?}
          ?? ??? ?if (contextpath == null)
          ?? ??? ??? ?throw new ApplicationRuntimeException(
          ?? ??? ??? ??? ??? ?"Error occured when getting context path.");

          ?? ??? ?contextpath = contextpath.substring(contextpath.indexOf("/") + 1);
          ?? ??? ?contextpath = contextpath.substring(contextpath.indexOf("/"));
          ?? ??? ?GlobalAssets.init(contextpath);
          ?? ?}

          }


          其它:研究tapestry-4.0.jar/META-INF/下其它配置文件,可以對tapestry的眾多功能進行擴展。

          標準組件的擴展:tapestry 框架所提供的組件稱為標準組件,它是在Framework.library中進行定義的,如果想修改標準組件,則可以修改這個文件,設定 specification-path為合適的 classpath即可;更好的辦法是新建一個庫定義mylib.library,其中將標準組件的名字換成新的名字,如:
          <component-type type="Form2" specification-path="/com/mycom/web/tapestry/form/Form.jwc"/>
          引用時使用Form2即可,這樣做可以保證框架的完整性,但是需要增加庫ID,如:form@mylib:Form。

          注意:也可以將以下一行代碼放入自己的application文件中,這種做法最佳!
          <component-type type="Form" specification-path="/com/mycom/web/tapestry/form/Form.jwc"/>


          結束語:希望本篇短文能起到拋磚引玉的作用,引導大家對tapestry的諸多功能進行隨心所欲的定制和擴展。到目前為止,對應Tapestry4.0的擴展與修改都不需要修改tapestry-4.0.jar文件,歡迎留言進行討論。
          posted on 2007-01-29 18:26 Tapestry 閱讀(605) 評論(0)  編輯  收藏 所屬分類: Tapestry
          主站蜘蛛池模板: 虎林市| 泰宁县| 金乡县| 静乐县| 铜陵市| 玛沁县| 三门县| 冷水江市| 通榆县| 临高县| 从江县| 民和| 青河县| 定襄县| 怀远县| 广德县| 益阳市| 马关县| 张家界市| 双流县| 西平县| 塔河县| 内丘县| 隆子县| 大邑县| 永定县| 阳高县| 城口县| 灵川县| 海门市| 尼玛县| 九江市| 嘉黎县| 慈溪市| 红原县| 紫阳县| 海淀区| 绍兴县| 梅州市| 定日县| 德江县|