OFBiz框架实现分页效果
2015-12-03 19:10
489 查看
1.freemarker写的ftl文件
susake.ftl 展示效果
button.ftl 用作点击分页的页数链接
susakescreen.xml
performFindList.java
performFind.java
效果:
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; }
效果:
相关文章推荐
- phpstore设置
- Spark高级数据分析中文版-读者交流
- nginx 源码学习笔记(十七)—— ngx_worker_process_cycle子进程执行
- javascript字符串单引号与双引号的区别
- 牛客堂刷题之最大乘积
- 02-SpringMVC_获得用户请求
- Linux_LDAP+NFS+autofs
- 公钥和私钥
- 轻松学习JavaScript十:JavaScript的Date对象制作一个简易钟表
- Git 常用命令笔记
- 蓝桥杯算法提高 -- 金陵十三钗
- Android studio debug使用正式的签名
- Android PopupWindow with ListView的一些问题
- 阶乘
- ASP.NET]ASP.NET C# 用 Print2Flash 实现在线预览 Word、PPT、PDF 等
- oracle 基于PLSQL实现发送邮件 UTL_SMTL
- 快速排序
- 将浏览器窗口变成简单的文本编辑器
- Remove Element 移除元素
- 【HLG 1572】表达式计算