一个免费wap站

源代码在线查看: categorylisttag.java

软件大小: 2680 K
上传用户: newyearday
关键词: wap
下载地址: 免注册下载 普通下载 VIP

相关代码

				package com.eline.wap.resource.taglib;
				
				import java.util.Collection;
				
				import javax.servlet.http.HttpServletRequest;
				
				import com.eline.wap.common.model.Page;
				import com.eline.wap.common.taglib.ListTag;
				import com.eline.wap.resource.client.CategoryHelper;
				import com.eline.wap.resource.model.CategoryCondition;
				
				public class CategoryListTag extends ListTag {
				
					/**
					 * 
					 */
					private static final long serialVersionUID = -8289710598646414274L;
				
					private String prefix;
					private boolean hasNext = false;
					
					private int pageItems;			// 页面大小
					private int pageNum		= 0;	// 页号
					private int parentId	= -1;
					private int type		= -1;
					private boolean isActiveOnly	= false;
				
					
					public CategoryListTag() {
						prefix = "CategoryList_";
					}
				
					protected boolean needsNextForm() {
						return hasNext;
					}
				
					protected void initParamPrefix() {
						super.paramPrefix = this.prefix;
					}
				
					protected Collection findCollection() throws Exception {
						Collection coll = null;
						Page page = null;
						
						HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
						
						// 保证每次调用该列表页面时总显示第一页
						if(request.getParameter(prefix + "pageIndex") == null || request.getParameter(prefix + "pageIndex").equals("")
								|| request.getParameter(prefix + "pageIndex").equalsIgnoreCase("null"))
							pageIndex = 0;
				
						// 根据页面中查询条件形成查询值对象
						CategoryCondition condition = fillQueryCondition();
				
						// 查询结果
						CategoryHelper ch = new CategoryHelper();
						int start = pageIndex * pageSize;
						page = ch.searchCategories(condition, start, pageSize);
						coll = page.getItems();
						
						// 为基类相应属性赋值,写共几条记录,共几页第几页用
						totalRecords = page.getTotalRecords();	// 共有多少条记录
						totalPages = (totalRecords + pageSize - 1) / pageSize;	// 共有多少页
						
						// 是否有下页
						hasNext = ((pageIndex + 1) < totalRecords) ? true : false;
				
						return coll;
					}
				
					private CategoryCondition fillQueryCondition() {
						CategoryCondition condition = new CategoryCondition();
						boolean hasCondition = false;
						
						if (parentId >= 0) {
							condition.setParentId(parentId);
							hasCondition = true;
						}
						if (isActiveOnly == false) {
							condition.setActiveOnly(false);
							hasCondition = true;
						}
						if (this.type != -1) {
							condition.setType(type);
							hasCondition = true;
						}
						
						return hasCondition ? condition : null;
					}
				
					public void setPageItems(int pageItems) {
						this.pageItems = pageItems;//StringUtils.getInt(pageItems, 10);
						super.pageSize = this.pageItems;
					}
				
					public void setPageNum(int pageNum) {
						this.pageNum = pageNum;//StringUtils.getInt(pageNum, 0);
						super.pageIndex = this.pageNum;
					}
				
					public void setParentId(int parentId) {
						this.parentId = parentId;//StringUtils.getInt(parentId, 0);
					}
				
					public void setType(int type) {
						this.type = type;//StringUtils.getInt(type, -1);
					}
				
					public void setActiveOnly(boolean isActiveOnly) {
						this.isActiveOnly = isActiveOnly;//StringUtils.getBoolean(isActiveOnly, true);
					}
				
					
				}
							

相关资源