Ofbiz 分页代码

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 分页代码)