數據加載中……
          sitemesh 簡單入門 之二
          2008年4月16日  Edited By DingDangXiaoMa 
           (1)printable 裝飾及 page 用法。
          當要打印頁面內容時,不想要一些邊邊框框。只關注想要的內容,設置為printable decorators 即可。
          sitemesh 設置方法如下:
          setemesh.xml
          <mapper class="com.opensymphony.module.sitemesh.mapper.PrintableDecoratorMapper">
                      <param name="decorator" value="printable" />
                      <param name="parameter.name" value="printable" />
                      <param name="parameter.value" value="true" />
          </mapper>
          上面代碼為設置  打印的屬性及參數。?printable=true鏈接到打印模式上。
          decorators.xml
           <decorator name="printable" page="printable.jsp"/>
          功能:將name="printable" 的裝飾映射到printable.jsp上。
          printable.jsp
          <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
          <html>
              
          <head>
                  
          <title><decorator:title default="NO Title" /></title>
                  
          <decorator:head />
              
          </head>
              
          <body>
                  
          <h1><decorator:title  default="No Title"/></h1>
                  
          <p align="right"><i>(printable version)</i></p>
                  
          <decorator:body />
              
          </body>
          </html>
          這是參照官方上的例子的printable.jsp.注意。當鏈接指向時,沒有標題時,顯示No Title .當沒有body部分時,則會出現null point error(我出現了這個錯誤,不知道是不是我機子的問題)
          按照上述配置后:當訪問:http://localhost/sitemesh/index.jsp?printable=true 時,就只能顯示index.jsp未被修飾的數據。
          再進行修改就是在頁面上加一個超級鏈接到些頁面打印狀態。
          在decorators/main.jsp中加入以下代碼;
                  <decorator:usePage id="p" />
                  
          <%
                      HttpServletRequest req 
          = p.getRequest();
                      StringBuffer printUrl 
          = new StringBuffer();
                      printUrl.append( req.getRequestURI() );
                      printUrl.append(
          "?printable=true");
                      
          if (request.getQueryString()!=null) {
                          printUrl.append(
          '&');
                          printUrl.append(request.getQueryString());
                      }
                  
          %>
                  
          <p align="right"><a href="<%= printUrl %>">printable version</a> ]</p>
          這樣就在每個頁面都添加上了,打印式的超級鏈接。 <decorator:usePage id="p" /> 是獲得了頁面的page對象。
          (2)page:applyDecorator 用法:把某一個頁面進行某種樣式的映射。<page:applyDecorator page="*.jsp" name="*" />
          把*.jsp映射到decorators.xml 中定義的* 裝飾上。
          例子:
          <page:applyDecorator name="panel" page="/date.jsp" >


          posted on 2008-04-16 18:07 叮當小馬 閱讀(345) 評論(0)  編輯  收藏 所屬分類: OpenSymphony


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 育儿| 湟源县| 尖扎县| 垣曲县| 临西县| 三穗县| 莆田市| 贵定县| 大连市| 泗阳县| 洪雅县| 广南县| 平昌县| 黄陵县| 阿坝县| 江门市| 志丹县| 延津县| 凤阳县| 滦平县| 鄂温| 景泰县| 从江县| 平阴县| 南通市| 宁陕县| 鄂伦春自治旗| 霍林郭勒市| 增城市| 沈阳市| 昌乐县| 鹤庆县| 卓资县| 青州市| 天全县| 山阳县| 龙陵县| 囊谦县| 吉隆县| 新龙县| 荥经县|