read-Atleap-3-Tiles学习

read-Atleap-Tiles学习

v Atleap没有像AppFuse那样使用sitemesh分离显示格式和布局,而是采用了strutsTiles.

运行用户将内容和布局分离

模板就是一个使用JSP自定义标记符库描述页面布局的JSP页面。

模板充当的定义的角色,它定义了应用程序的外观而不指定内容。在运行期,用户可以将内容插入到模板页面,并且,一个或多个页面可以使用同一个模板。

 

 

tiles-config.xml时定义配置文件

   <!-- Core layout -->

    <!definition标记用来创建一个tile作为一个定义的bean,在要求的scope内,该

        Bean以指定的id保存

-->

    <definition name=

".coreLayout" path="/WEB-INF/pages/layouts/core/coreLayout.jsp">

<!put标记将属性传递给一个tile组件-->

        <put name="titleKey"/>

        <put name="content" />

<!pubList创建一个列表,该列表作为属性传递给

列表元素使用add标记添加。Value是用来添加的值,可以是StringObject

-->

        <putList name="leftLayoutBlocksList">

            <add value=".loginForm" />

            <add value=".core.menu" />

        </putList>

        <putList name="rightLayoutBlocksList">

            <add value=".searchForm" />

            <add value=".switchLocaleForm" />

            <add value=".editModeForm" />

        </putList>

        <!-- Default Javascript Files -->

        <putList name="layoutScripts">

            <add value="/scripts/core/klayers.js"/>

            <add value="/scripts/core/global.jsp"/>

            <add value="/scripts/core/validator.jsp"/>

            <add value="/scripts/core/helptip.js"/>

            <add value="/scripts/core/luceneQueryValidator.jsp"/>

        </putList>

        <!-- Default Stylesheet Files -->

        <putList name="layoutStyles">

            <add value="/styles/core/core.css"/>

            <add value="/styles/core/helptip.css"/>

        </putList>

    </definition>

以下语句声明在页面使用一个属性值

<tiles:useAttribute id="leftLayoutBlocks" name="leftLayoutBlocksList"

classname="java.util.List" ignore="true"/>

 

 

以下语句声明创建一个组件定义

<tiles:insert definition="${layoutBlock}" />

 

 

tiles:insert插入一个tile组件,insert标记负责将内容插入到一个页面中。

<c:forEach items="${leftLayoutBlocks}" var="layoutBlock">

<tiles:insert definition="${layoutBlock}" />

</c:forEach>

 

 

以下语句获取由put标记放在请求作用域的内容

<tiles:get name="content" />

 

 

v Atleap 中新闻列表显示之Struts Tiles分析

i)              Tiles中的coreLayout定义

<definition name=

".coreLayout" path="/WEB-INF/pages/layouts/core/coreLayout.jsp">

<!put标记将属性传递给一个tile组件-->

        <put name="titleKey"/>

       <!需要显示的主体内容页面属性,在此为要显示新闻列表-->

        <put name="content" />

ii)           进入根下的index.jsp页面

<logic:redirect action="index" />

iii)        struts-config.xml中的配置

   <!-- Action to index -->

    <action path="/index" type="org.apache.struts.actions.ForwardAction"

        parameter=".core.index" />

iv)           tiles-config.xml中的配置

<!--.core.index继承于.coreLayout-->

    <definition name=".core.index" extends=".coreLayout">

        <put name="content" value="/WEB-INF/pages/core/index.jsp" />

    </definition>

v)              /WEB-INF/pages/core/index.jsp

<%@ include file="/WEB-INF/pages/common/taglibs.jsp"%>

<atleap:errors />

<a href="javascript:void(printSpecial())">

    <img src="<c:url value="/images/core/print.gif" />" width="17" height="13" border="0" />

</a>

<div id="printReady">

    <atleap:contentIterator identifier="body" index="index" ignore="true">

        <atleap:content identifier="body" index="${index}"/>

        <br />

    </atleap:contentIterator>

</div>

<div>

    <!—insert标记符提供一个布局,并且允许用put标记传递内容给布局-->

    <tiles:insert definition=".news.list" />

</div>

vi)           Tiles-config.xml.news.list"的配置

    <definition name=".news.list" path="/WEB-INF/pages/news/newsList.jsp" controllerClass="com.blandware.atleap.webapp.action.news.NewsListController" />

 

 

vii)       /WEB-INF/pages/news/newsList.jsp:真正显示新闻列表的地方

<%@ include file="/WEB-INF/pages/common/taglibs.jsp"%>

<atleap:constants className="com.blandware.atleap.webapp.util.news.NewsModuleWebConstants" var="NEWS_ITEMS_COLLECTION_KEY" />

<bean:size id="newsItemsCollectionSize" collection="${requestScope[pageScope.NEWS_ITEMS_COLLECTION_KEY]}" />

<c:if test="${newsItemsCollectionSize > 0}">

    <h3>

        <bean:message key="news.listItems" />

    </h3>

</c:if>

<table cellpadding="0" cellspacing="0" border="0" class="tableView">

    <c:forEach var="newsItem" items="${requestScope[pageScope.NEWS_ITEMS_COLLECTION_KEY]}">

        <tr>

            <th align="left">

                <atleap:formatDate value="${newsItem.publicationDate}" />&nbsp;&nbsp;<atleap:fieldValue valueMap="${newsItem.title}" ignore="true" />

            </th>

        </tr>

        <tr>

            <td>

                <atleap:edit action="/news/callUpdateItem?id=${newsItem.id}">

                   <div>

                       <atleap:fieldValue valueMap="${newsItem.annotation}" ignore="true" filter="false" />

                   </div>

                   <div>

                       <atleap:message key="button.newsItemForm.moreInfo" var="moreInfoMsg"/>

                       <a href="${ctxPath}${newsItem.uri}" title="${moreInfoMsg}">

                           ${moreInfoMsg}

                       </a>

                   </div>

                </atleap:edit>

            </td>

        </tr>

    </c:forEach>

</table>

<c:if test="${newsItemsCollectionSize > 0}">

    <html:link action="news/showArchive"><bean:message key="news.archive" /></html:link>

</c:if>

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值