云自無心水自閑

          天平山上白云泉,云自無心水自閑。何必奔沖山下去,更添波浪向人間!
          posts - 288, comments - 524, trackbacks - 0, articles - 6
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          Tapestry最新版5.1.0.5教程(四)

          Posted on 2009-06-20 19:57 云自無心水自閑 閱讀(2534) 評論(3)  編輯  收藏 所屬分類: Java心得體會Tapestry

          1、Tapestry組件的寫法
          a、<t:textfield t:id="userName" t:value="jack"/>,這樣的寫法的優點是,看上去比較直觀,與Struts等Web框架的一致。但是缺點就是,使用瀏覽器(或者美工)直接看頁面的時候,瀏覽器無法正確顯示這個組件。
          b、<input type="text" t:type="textfield" t:id="userName" t:value="jack"/>這樣寫的話,瀏覽器就能正常顯示一個文本輸入框了。這也是Tapestry一直鼓吹的一大優點之一。
          c、在Java類中使用注解來聲明組件。這種方法我個人并不推薦,只是一種選擇,并不直觀也不方便。
          d、Tapestry組件標簽是不區分大小寫的。
          2、組件參數的前綴。從官方文檔來看,參數的前綴還挺多的:
          Prefix        Description
          asset        The relative path to an asset file (which must exist).
          block        The id of a block within the template.
          component        The id of another component within the same template.
          context        Context asset: path from context root.
          literal        A literal string.
          nullfieldstrategy        Used to locate a pre-defined NullFieldStrategy
          message        Retrieves a value from the component's message catalog.
          prop        A property expression to read or update.
          translate        The name of a configured translator.
          validate        A validator specification used to create some number of field validators.
          var        Allows a render variable of the component to be read or updated.
          但最最常用的只有2個:prop和literal
          簡單的說:prop表示這是一個變量名,literal表明這是一個常量
          比如說select這個組件,它的基本寫法是: <t:select t:id="color" model="literal:Red,Green,Blue" label="Colour:"/>
          查看select的參考文檔,model這個參數的缺省前綴是prop,所以如果直接寫model="red"的話,Tapestry會認為red是一個變量名,會調用頁面對應類的getRed()方法來獲得一個列表。所以,此處如果想使用一個常量的話,需要顯示指明literal前綴。而label的缺省前綴是literal,所以直接這樣寫就沒有問題。
          3、Label,顯示一個標簽,一般在需要多語言的環境下或者與textField配合使用。
          <t:label t:for="userName">Label for the user name</t:label> Lable組件有一個t:for的屬性,這個屬性的值一般是一個textField的id。我們可以注意到Lable標簽里寫一段文字,這一段文字在頁面部署運行后是不會顯示的,寫在這里,純粹是給美工這樣的靜態頁面瀏覽者看的。在實際運行中這一段文字會被替代。替代的內容就是t:for屬性對應的TextField組件的t:id的值,比如:userName。當然Tapestry會自動把userName分成兩個單詞,而且把user的首字母大寫。
          如果根據t:id生成的lable不符合要求,可以有另一種選擇:直接在textField中指定label:
          <input type="text" t:type="textField" t:id="userName" t:label="Input User Name" t:value="jack"/>
          4、PageLink,用于顯示一個鏈接,點擊后,跳轉到指定頁面
          <a href="#" t:type="pageLink" t:page="register">Register</a>
          5、ActionLink,用于顯示一個鏈接,點擊后,運行一個可以帶有參數的指令。
          <a href="#" t:type="actionLink" t:context="id" t:id="clickLink">
                  ${user.id}
              </a>
            如果一個參數不夠,比如,只用一個id不能唯一確定一個用戶,必須結合部門id才能唯一確定用戶的話,那么可以這樣做:
            <a href="#" t:type="actionLink" t:context="userContext" t:id="clickLink">delete</a>
            相應的在java class中需要添加一個方法:getUserContext()
            public Object[] getUserContext() {
               return new Object[] {user.id, department.id};
            }
          6、Loop
          Loop并不是一個真正的Form控件,嚴格說起來是一種邏輯控制語句。語法如下:
          <t:loop source="userList" value="user">
              <td>${user.name}</td>
          </t:loop>
          7、Radio & Radio
                      <t:radiogroup t:id="type">
                          <t:radio t:id="masterCard"/>
                          <t:label for="masterCard"/>
                          <t:radio t:id="visa"/>
                          <t:label for="visa"/>
                          <t:radio t:id="amex"/>
                          <t:label for="amex"/>
                          <t:radio t:id="dinersClub"/>
                          <t:label for="dinersClub"/>
                          <t:radio t:id="discover"/>
                          <t:label for="discover"/>
                      </t:radiogroup>

          8、CheckBox
          <t:checkbox t:id="showall" onclick="this.form.submit();"/> <t:label for="showall"/>
          9、Select
          <t:select t:id="color" model="literal:Red,Green,Blue"/>




          評論

          # re: Tapestry最新版5.1.0.5教程(四)  回復  更多評論   

          2009-07-06 10:46 by skybirds
          麻煩tapestry5.1的教程能出快點不?

          # re: Tapestry最新版5.1.0.5教程(四)  回復  更多評論   

          2010-01-10 13:48 by 賈俊超
          很好的內容,太少了,有很有的課件或者視頻的就好了!

          # re: Tapestry最新版5.1.0.5教程(四)  回復  更多評論   

          2010-03-03 00:38 by idreamer
          非常感謝。我做畢業設計,web層用的就是tapestry。不喜歡struts2,感覺很亂,我和作者的想法不一樣。本來打算自己做個mvc的,叫beanstruts,最后發現好多東西需要做,緩存,注入(事件注入已經實現),驗證。。。最后發現了tapestry感覺思想上很容易接受,不過用起來真不容易。
          主站蜘蛛池模板: 江门市| 富民县| 江源县| 绥阳县| 阳城县| 丹棱县| 青铜峡市| 保康县| 英山县| 共和县| 安吉县| 东兰县| 沈阳市| 灵宝市| 昭觉县| 台东县| 巨鹿县| 永春县| 怀化市| 贵港市| 达尔| 安西县| 陇西县| 普定县| 遂溪县| 当涂县| 德惠市| 报价| 麻江县| 会同县| 乌海市| 林芝县| 定远县| 华阴市| 利津县| 哈巴河县| 永仁县| 芷江| 绥芬河市| 民丰县| 鄂伦春自治旗|