OFBiz框架实现分页效果

4 篇文章 0 订阅
2 篇文章 0 订阅

1.freemarker写的ftl文件

susake.ftl 展示效果

<div id="findEmployment" >
<form >
<#if listIt?has_content>
<table border="1">
 总的页数:<#if listSize%10 gt 0 > ${listSize%10+2} <#else> ${listSize%10+1} </#if>
 总的条数:${listSize}
 当前页数:${viewIndex+1}
当前页面的条数:<#if listSize/10 gt (viewIndex+1)> 10 <#else> ${listSize%10} </#if> 

 <tr>
 <th>用户</th>
 <th>日期</th>
 <th>新订单</th>
 <th>订单</th>
 <th>账户</th>
 <th>信息</th>
 <th>标签</th>
 <th>账户1</th>
 <th>信息1</th>
 <th>标签1</th>
 <th>操作</th>
 </tr>

<#list listIt as item>

 <tr>
 <td>${item.ordercount}</td>
 <td>${item.date}</td>
 <td>${item.qordercount}</td>
 <td>${item.usercount}</td>
 <td>${item.qsercount}</td>
 <td>${item.zsercount}</td>
 <td>${item.zordercount}</td>
 <td>${item.qorderrate}</td>
 <td>${item.userrate}</td>
 <td>${item.tag}</td>
 <td>
    <a id="deleteorder" 
   href="deleStoreAstntSusakeList?orderCount=${item.ordercount}">删除 </a>
    <a id="updateorder"
     href="UpdateStoreAstntSusakeList?ordercount=${item.ordercount}">修改 </a>
     <input type="hidden" id="pageNumber" name="VIEW_INDEX" value="${(viewIndex)!'0'}" />
     <input type="hidden" id="pageSize" name="VIEW_SIZE" value="${(viewSize)!'10'}" />
 </td>
 </tr>

</#list>
</table>
</#if>
         <#assign paginationUrl="SusakeGroupList${(conditionUrl)!}">
         <#import "component://gbcm/webapp/gbcm/views/includes/button.ftl" as p> 
         <@p.SusakePage requestUrl=paginationUrl listSize=listSize/>
</form>
</div>

button.ftl 用作点击分页的页数链接

<#--pagination-->
<#macro SusakePage requestUrl listSize=listSize viewIndex=viewIndex viewSize=viewSize noConditionFind="Y" filterParams="">
    <#assign conditionUrl = "">
    <#if listSize gt 0 && viewSize gt 0>

        <#if filterParams?has_content>
            <#assign filterParamsList = Static["org.ofbiz.gbsm.utils.ServletUtil"].getStringSpitList(filterParams)/>
            <#list filterParamsList as item>
                <#if parameters.get("${(item)!}")?has_content>
                    <#assign conditionUrl = conditionUrl + "&${(item)!}=" + parameters.get("${(item)!}")>
                </#if>
            </#list>
        </#if>

        <#assign x=Static["java.lang.Math"].floor(listSize/viewSize)>
        <#if listSize gt (x*viewSize)><#assign x=x+1></#if>

        <#if requestUrl?contains("?")>
            <#assign tmpUrl = requestUrl + "&noConditionFind="+noConditionFind+"${('&'+conditionUrl)?default('')}&VIEW_SIZE=${viewSize}&VIEW_INDEX="/>
        <#else>
            <#assign tmpUrl = requestUrl + "?noConditionFind="+noConditionFind+"${('&'+conditionUrl)?default('')}&VIEW_SIZE=${viewSize}&VIEW_INDEX="/>
        </#if>

        <div class="gb_pagination">  
            <#if (viewIndex gt 0)>
                <a class="previousPage" href="${tmpUrl}${viewIndex-1}"></a>
            <#else>
                <span class="previousPage"></span>
            </#if>

            <#if (x gt 10) &&  (viewIndex gt 5)>
                <#assign start = viewIndex - 4>
                <#assign end = viewIndex + 5>
                <#if (start lt 1)><#assign start = 1></#if>
                <#if (end gt x)><#assign end = x></#if>
            <#else>
                <#assign start = 1>
                <#if (x < 10)>
                    <#assign end = x>
                <#else>
                    <#assign end = 10>
                </#if>
            </#if>

            <#if viewIndex != 0 && viewIndex gt 5 && x gt 10><a href="${tmpUrl}0" class="flag_pg">1</a></#if>
            <#if viewIndex gt 5 && x gt 10><span class="page-break">...</span></#if>
            <#list start..end as i>
                <#if i == (viewIndex+1)><span class="currentPage">${i}</span><#else><a href="${tmpUrl}${i-1}" class="flag_pg">${i}</a></#if>
            </#list>
            <#if end lt x && x gt 10><span class="page-break">...</span></#if>
            <#if end != x><a href="${tmpUrl}${x-1}" class="flag_pg">${x}</a></#if>
            <#if ((viewIndex+1) lt x)>
                <a class="nextPage" href="${tmpUrl}${viewIndex+1}"></a>
            <#else>
                <span class="nextPage"></span>
            </#if>
        </div>
    </#if>
</#macro>

susakescreen.xml

<screen name="SusakeFindParty">        
        <section>
        <actions>
               <set field="parameters.noConditionFind" value="Y" />
                <set field="parameters.statusId" value="PARTY_ENABLED" />
                <set field="p_Ctx" from-field="parameters" />

                <set field="p_Ctx.partyIdFrom_op" value="empty" />  <!-- 查询为空的 -->
                <set field="viewIndex" from-field="parameters.VIEW_INDEX" type="Integer" default-value="0" />
                <set field="viewSize" from-field="parameters.VIEW_SIZE" type="Integer" default-value="10" />
                <set field="sortField" value="createdDate" />
                <service service-name="performFindList" result-map="result">
                    <field-map field-name="inputFields" from-field="p_Ctx" />
                    <field-map field-name="entityName" value="SusakeCount" />
                    <field-map field-name="orderBy" from-field="ordercount" />
                    <field-map field-name="viewIndex" from-field="viewIndex" />
                    <field-map field-name="viewSize" from-field="viewSize" />
                </service>
                <set field="listIt" from-field="result.list" />
                <set field="listSize" from-field="result.listSize" />
            </actions>
            <widgets>
                <decorator-screen name="AjaxCommonDecorator" location="${parameters.mainDecoratorLocation}">
                    <decorator-section name="body">
                        <platform-specific>
                            <html>
                                <html-template location="component://gbsm/webapp/gbsm/views/party/susake.ftl" />
                            </html>
                        </platform-specific>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>

performFindList.java

public static Map<String, Object> performFindList(DispatchContext dctx, Map<String, Object> context) {
        Integer viewSize = (Integer) context.get("viewSize");
        if (viewSize == null) viewSize = Integer.valueOf(20);       // default
        context.put("viewSize", viewSize);
        Integer viewIndex = (Integer) context.get("viewIndex");
        if (viewIndex == null)  viewIndex = Integer.valueOf(0);  // default
        context.put("viewIndex", viewIndex);

        Map<String, Object> result = performFind(dctx,context);

        int start = viewIndex.intValue() * viewSize.intValue();
        List<GenericValue> list = null;
        Integer listSize = null;
        try {
            EntityListIterator it = (EntityListIterator) result.get("listIt");
            list = it.getPartialList(start+1, viewSize); // list starts at '1'
            listSize = it.getResultsSizeAfterPartialList();
            it.close();
        } catch (Exception e) {
            Debug.logInfo("Problem getting partial list" + e,module);
        }

        result.put("listSize", listSize);
        result.put("list",list);
        result.remove("listIt");
        return result;
    }

performFind.java

 public static Map<String, Object> performFind(DispatchContext dctx, Map<String, ?> context) {
        String entityName = (String) context.get("entityName");
        String orderBy = (String) context.get("orderBy");
        Map<String, ?> inputFields = checkMap(context.get("inputFields"), String.class, Object.class); // Input
        String noConditionFind = (String) context.get("noConditionFind");
        String distinct = (String) context.get("distinct");
        List<String> fieldList =  UtilGenerics.<String>checkList(context.get("fieldList"));
        GenericValue userLogin = (GenericValue) context.get("userLogin");
        Locale locale = (Locale) context.get("locale");
        if (UtilValidate.isEmpty(noConditionFind)) {
            // try finding in inputFields Map
            noConditionFind = (String) inputFields.get("noConditionFind");
        }
        if (UtilValidate.isEmpty(noConditionFind)) {
            // Use configured default
            noConditionFind = UtilProperties.getPropertyValue("widget", "widget.defaultNoConditionFind");
        }
        String filterByDate = (String) context.get("filterByDate");
        if (UtilValidate.isEmpty(filterByDate)) {
            // try finding in inputFields Map
            filterByDate = (String) inputFields.get("filterByDate");
        }
        Timestamp filterByDateValue = (Timestamp) context.get("filterByDateValue");

        Integer viewSize = (Integer) context.get("viewSize");
        Integer viewIndex = (Integer) context.get("viewIndex");
        Integer maxRows = null;
        if (viewSize != null && viewIndex != null) {
            maxRows = viewSize * (viewIndex + 1);
        }

        LocalDispatcher dispatcher = dctx.getDispatcher();

        Map<String, Object> prepareResult = null;
        try {
            prepareResult = dispatcher.runSync("prepareFind", UtilMisc.toMap("entityName", entityName, "orderBy", orderBy,
                                               "inputFields", inputFields, "filterByDate", filterByDate, "noConditionFind", noConditionFind,
                                               "filterByDateValue", filterByDateValue, "userLogin", userLogin,
                                               "locale", context.get("locale"), "timeZone", context.get("timeZone")));
        } catch (GenericServiceException gse) {
            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonFindErrorPreparingConditions", UtilMisc.toMap("errorString", gse.getMessage()), locale));
        }
        EntityConditionList<EntityCondition> exprList = UtilGenerics.cast(prepareResult.get("entityConditionList"));
        List<String> orderByList = checkList(prepareResult.get("orderByList"), String.class);

        Map<String, Object> executeResult = null;
        try {
            executeResult = dispatcher.runSync("executeFind", UtilMisc.toMap("entityName", entityName, "orderByList", orderByList,
                                                                             "fieldList", fieldList, "entityConditionList", exprList,
                                                                             "noConditionFind", noConditionFind, "distinct", distinct,
                                                                             "locale", context.get("locale"), "timeZone", context.get("timeZone"),
                                                                             "maxRows", maxRows));
        } catch (GenericServiceException gse) {
            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonFindErrorRetrieveIterator", UtilMisc.toMap("errorString", gse.getMessage()), locale));
        }

        if (executeResult.get("listIt") == null) {
            if (Debug.verboseOn()) Debug.logVerbose("No list iterator found for query string + [" + prepareResult.get("queryString") + "]", module);
        }

        Map<String, Object> results = ServiceUtil.returnSuccess();
        results.put("listIt", executeResult.get("listIt"));
        results.put("listSize", executeResult.get("listSize"));
        results.put("queryString", prepareResult.get("queryString"));
        results.put("queryStringMap", prepareResult.get("queryStringMap"));
        return results;
    }

效果:
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值