码迷,mamicode.com
首页 > 其他好文 > 详细

Ofbiz 分页代码

时间:2015-06-17 18:20:15      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

Delegator delegator = (Delegator) request.getAttribute("delegator");
LocalDispatcher dispatcher = (LocalDispatcher) request
.getAttribute("dispatcher");
HttpSession session = request.getSession();
GenericValue userLogin = (GenericValue) session
.getAttribute("userLogin");


// 分页相关
String pageNumber = request.getParameter("pageNumber");
String pageSize = request.getParameter("pageSize");


// 当前页
int intPage = Integer.parseInt((pageNumber == null || pageNumber
.equals("0")) ? "1" : pageNumber);
// 每页显示条数
int number = Integer
.parseInt((pageSize == null || pageSize.equals("0")) ? defaultPageSize
: pageSize);
// 每页的开始记录 第一页为1 第二页为number +1
int lowIndex = (intPage - 1) * number + 1;
int highIndex = intPage * number;
EntityListIterator eli = null;
EntityFindOptions findOptions = new EntityFindOptions(true,
EntityFindOptions.TYPE_SCROLL_SENSITIVE,
EntityFindOptions.CONCUR_READ_ONLY, true);
// 根据用户loginId判断用户是否拥有系统管理员角色,如果有就任务是系统管理员,查询所有角色。


List<EntityCondition> connList = FastList.newInstance();
try {
TransactionUtil.begin();
eli = delegator.find("SecurityGroup",
EntityCondition.makeCondition(connList), null, null, null,
findOptions);
List<GenericValue> roleList = eli.getPartialList(lowIndex, number);


int totalPage = (eli.getResultsSizeAfterPartialList() + number - 1)
/ number;
request.setAttribute("pageSize", number);
request.setAttribute("totalPage", totalPage);
request.setAttribute("currentPage", intPage);
request.setAttribute("roleList", roleList);
TransactionUtil.commit();
} catch (GenericEntityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
try {
TransactionUtil.rollback();
} catch (GenericTransactionException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} finally {
try {
if (eli != null) {
eli.close();
}
} catch (GenericEntityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

Ofbiz 分页代码

标签:

原文地址:http://blog.csdn.net/kingzuo/article/details/46535839

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!