當前訪問本站: hits

          yjhmily

          堅持走自己的路……

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            100 Posts :: 8 Stories :: 353 Comments :: 0 Trackbacks
          這兩天在給公司的新項目搭框架,在配tiles框架的時候發現一個小問題:
          ??? 比如開發團隊一共5人,每人10個頁面,如果按照簡單的tiles框架配置方法,每個<definition/>中都會產生很多重復的<put name="top" value="xxx.jsp"/>代碼,導致tiles-defs.xml文件不段的膨脹.
          ??? 仔細想了想tiles框架的原理,如果tiles支持嵌套功能的話,雖然tiles-defs.xml文件中的<definition/>個數沒辦法減少,但
          每個<definition/>中的<put/>是完全可以精簡的.即需要改變哪個頁面就只配置哪個頁面;
          ??? 查了一下struts的文檔,雖然沒找到tiles框架的嵌套功能,卻找到了組合和擴展(我喜歡叫它繼承),同樣能解決問題!

          ?
          ?? 下面我簡單介紹一下它們各自的用法:(頁面布局見下圖)

          tiles_layout.jpg

          一,Tiles組件的模板

          ??? 這里我們需要設置兩個layout模板,分別為parent_layout.jsp和child_layout.jsp
          ???
          ??? parent_layout.jsp
          ????
          <!--parent_layout.jsp-->
          <body>
          ????
          <div>
          ????????
          <!--頂部菜單區域-->
          ????
          <tiles:insert?attribute="top"?/>
          ????
          <!--左邊豎導航-->
          ????
          <tiles:insert?attribute="left"?/>
          ????????
          <!--右邊主內容區域-->
          ????????
          <tiles:insert?attribute="child"?/>
          ????????
          <!--底步區域-->
          ????
          <tiles:insert?attribute="foot"?/>
          ????
          </div>
          </body>

          ?? child_layout.jsp

          <!--child_layout.jsp-->
          <body>
          ????
          <div>

          ????
          <!--右邊主內容的tab區域-->
          ????
          <tiles:insert?attribute="tab"?/>
          ????
          <!--右邊主內容的content區域-->
          ????
          <tiles:insert?attribute="content"?/>
          ?????

          ????</div>
          </body>



          二,
          Tiles組件的組合
          ???
          ??? 根據以上模板的定義,在
          tiles-defs.xml文件中就可以這樣寫來實現Tiles的組合了:
          ???
          //?父級tiles模板配置
          <definition?name="parent"path="/parent_layout.jsp">
          <put?name="top"?value="/top.jsp"?/>
          <put?name="left"?value="/left.jsp"?/>
          <put?name="child"?value="child"?type="definition"/>?
          <put?name="foot"?value="/foot.jsp"?/>
          </definition>

          //?子級tiles配置
          <definition?name="child"path="/child_layout.jsp">
          <put?name="tab"?value="/tab.jsp"?/>
          <put?name="content"?value="/content.jsp"?/>
          </definition>

          ???
          三,Tiles組件的擴展(繼承)
          ???
          ??? 這里需要對以上的parent_layout模板做一些修改,并且不需要使用child_layout

          ??? 修改后的parent_layout.jsp
          ???
          <!--parent_layout.jsp-->
          <body>
          ????
          <div>
          ????????
          <!--頂部區域-->
          ????
          <tiles:insert?attribute="top"?/>
          ????
          <!--左邊豎導航-->
          ????
          <tiles:insert?attribute="left"?/>
          ????
          <!--右邊主內容區域-->
          ????????
          <tiles:insert?attribute="tab"?/>
          ????
          <tiles:insert?attribute="content"?/>
          ????????
          <!--底部區域-->
          ????????
          <tiles:insert?attribute="foot"?/>
          ????
          </div>
          </body>

          ??? 改完模板文件,下來該進行tiles的配置了;

          //?父級tiles模板配置
          <definition?name="parent"?path="/parent_layout.jsp">
          <put?name="top"?value="/top.jsp"?/>
          <put?name="left"?value="/left.jsp"?/>
          <put?name="tab"?value="/tab.jsp"?/>
          <put?name="content"?value=""?/>
          <put?name="foot"?value="/foot.jsp"?/>
          </definition>



          // 子級tiles模板配置
          <definition?name="child"?extends="parent">
          <put?name="content"?value="/content.jsp"?/>
          </definition>

          如上所示,大家在開發中,每個頁面只需要配置
          子級tiles的content.jsp就ok!


          以上是小弟對tiles框架的組合和繼承的簡單應用,歡迎大家指點!

          ???














          ???
          posted on 2006-10-25 19:06 kangxm 閱讀(4035) 評論(1)  編輯  收藏 所屬分類: J2EE

          Feedback

          #  2007-05-11 22:41 徐世賢
          英語是我的克星,我永遠都考不及格
            回復  更多評論
            

          # re: struts中tiles框架的組合與繼承 2008-08-20 11:40 王毅
          你好,我使用Tiles遇到個問題,幫我解決下:

          我的test.jsp大致如下:
          <html>
          <head>
          <title><tiles:getAsString name="title"/></title>
          </head>
          <body>
          <tiles:insert definition="tile.login" flush="true" />
          </body>
          </html>
          訪問時報錯:Error.tag getAsString


          去掉<tiles:getAsString name="title"/>一切正常


          在Struts-Config.xml中加入ForwardAction以.do形式訪問test.jsp仍然報錯



            回復  更多評論
            

          主站蜘蛛池模板: 关岭| 莱阳市| 得荣县| 郯城县| 九寨沟县| 林芝县| 龙川县| 洛浦县| 浠水县| 梁平县| 元阳县| 武威市| 河北省| 利辛县| 全南县| 大宁县| 搜索| 门头沟区| 高尔夫| 财经| 新河县| 深水埗区| 土默特右旗| 克山县| 海城市| 宝清县| 兴仁县| 浮梁县| 临漳县| 漳浦县| 秀山| 芦溪县| 元谋县| 张家口市| 崇阳县| 安康市| 临城县| 鞍山市| 漠河县| 抚州市| 滁州市|