close

  著手修改struts2-archetype-quickstart所預設的頁面。使用SiteMesh作為頁面配置,位在WEB-INF/decorators的main.jsp,而main.jsp引入/styles/main.css進行頁面配置,我當時卡在這裡調不出我要的頁面寬度。現在整理使用SiteMesh如下:

1.web.xml增加Filter:該filter會使用sitemesh.xml(和web.xml放一起)

<filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>

<filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
</filter-mapping>

2.sitemesh.xml:會指定要用的decorators file含路徑

<property name="decorators-file" value="/WEB-INF/decorators.xml"/>

3.decorators.xml:除了<excludes>所指定的url pattern外,其它url pattern均被裝配到main.jsp(預設位於/WEB-INF/decorators)。

<decorators defaultdir="/WEB-INF/decorators">
    <!-- Any urls that are excluded will never be decorated by Sitemesh -->
    <excludes>
        <pattern>/styles/*</pattern>
        <pattern>/scripts/*</pattern>
        <pattern>/images/*</pattern>
        <pattern>/dojo/*</pattern>
        <pattern>/struts/*</pattern>
    </excludes>

    <decorator name="main" page="main.jsp">
        <pattern>/*</pattern>
    </decorator>

</decorators>

  這裡的excludes的pattern要注意的是,是指url pattern,而非path pattern,比如<pattern>/jsp/login/*</pattern>,若是/login.action的forward導到/jsp/login下的jsp,/jsp/login下的jsp仍受SiteMesh裝配,因為url pattern是login.action,而非jsp/login/*。

  因此這種解法是,把/login.action列為excludes的pattern,假設login.action成功導到/jsp/login/ok.jsp,但url還是/login.action,因此ok.jsp不受SiteMesh裝配,但若ok.jsp內容是個redirect,重導對象就會被SiteMesh裝配,ok.jsp內容如下:

<% response.sendRedirect("index.action"); %>

4.main.jsp:會引入/styles/main.css作為主要CSS配置

<link href="<s:url value='/styles/main.css'/>" rel="stylesheet" type="text/css" media="all"/>

5.main.css:會include一堆其它css檔,主角是layout.css

@import url("tools.css");
@import url("typo.css");
@import url("forms.css");
@import url("layout-navtop-localleft.css");
@import url("layout.css");

6.layout.css:要調頁面寬度,就調div#page {width: 1280px; },原設定值是780像素。

 

呼呼!SiteMesh可以隱藏那麼多細節,不過看來應該不難用。剩十天不到,做不出來也等著當人肉串燒。

arrow
arrow
    全站熱搜

    Jemmy 發表在 痞客邦 留言(0) 人氣()