devicemodellisttag.java

来自「一个免费wap站」· Java 代码 · 共 127 行

JAVA
127
字号
package com.eline.wap.cmi.taglib;

import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.http.HttpServletRequest;

import com.eline.wap.cmi.client.MobileHelper;
import com.eline.wap.cmi.exceptions.CMIException;
import com.eline.wap.cmi.model.DeviceManufacturer;
import com.eline.wap.cmi.model.MobileCapabilityCondition;
import com.eline.wap.common.model.Page;
import com.eline.wap.common.taglib.ListTag;

public class DeviceModelListTag extends ListTag {

	/**
	 * 
	 */
	private static final long serialVersionUID = 9049979838876224486L;
	
	private int manufacturerId = -1;	// -1 = all
	private int[] selectedItems = new int[0];
	private String prefix;
	private boolean hasNext = false;
	
	public DeviceModelListTag() {
		prefix = "DeviceModelList_";
	}

	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;
		
		MobileCapabilityCondition condition = fillQueryCondition();

		MobileHelper helper = new MobileHelper();
		int start = pageIndex * pageSize;
		page = helper.searchBrowserCapabilities(condition, start, pageSize);
		coll = page.getItems();

		totalRecords = page.getTotalRecords();
		totalPages = (totalRecords + pageSize - 1) / pageSize;
		
		hasNext = ((pageIndex + 1) < totalRecords) ? true : false;

		return coll;
	}

	private MobileCapabilityCondition fillQueryCondition() {
		MobileCapabilityCondition condition = new MobileCapabilityCondition();
		boolean hasCondition = false;
		
		if (manufacturerId >= 0) {
			if (manufacturerId == 0) {
				condition.setDeviceManufacturer("CAN NOT BE FOUND");	// 会返回空列表
			} else {
				MobileHelper helper = new MobileHelper();
				try {
					DeviceManufacturer item = helper.getDeviceManufacturer(manufacturerId);
					if (item == null)
						throw new CMIException("can not found DeviceManufacturer for indexId = " + manufacturerId);
					condition.setDeviceManufacturer(item.getDeviceManufacturer());
				} catch (Exception e) {}
			}
			hasCondition = true;
		}
		
		return hasCondition ? condition : null;
	}

	public void setSelectedValues(String selectedValues) {
		System.out.println("setSelectedValues(\"" + selectedValues + "\")");
		if (selectedValues.length() < 1)
			return;
		String[] strArray = selectedValues.split(";");
		ArrayList coll = new ArrayList();
		for (int i = 0; i < strArray.length; i ++) {
			try { coll.add(new Integer(Integer.parseInt(strArray[i]))); }
			catch (NumberFormatException e) {}
		}
		this.selectedItems = new int[coll.size()];
		for (int i = 0; i < coll.size(); i ++) {
			this.selectedItems[i] = ((Integer) coll.get(i)).intValue();
		}
	}

	public int getManufacturerId() {
		return manufacturerId;
	}

	public void setManufacturerId(int manufacturerId) {
		this.manufacturerId = manufacturerId;
	}

	public int[] getSelectedItems() {
		return selectedItems;
	}

	public void setPageIndex(String pageIndex) {
		super.setPageIndex(pageIndex);
	}

	public void setPageSize(String pageSize) {
		super.setPageSize(pageSize);
	}

	public void setPageSize(int pageSize) {
		super.setPageSize(String.valueOf(pageSize));
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?