selecteditemsrangevalidatortag.java

来自「少有的JSf+Spring+Hibernate的网上购物车,适合要用jsf做项目」· Java 代码 · 共 69 行

JAVA
69
字号
/*
 * JCatalog Project
 */
package catalog.view.validator;

import javax.faces.validator.Validator;
import javax.faces.webapp.ValidatorTag;
import javax.servlet.jsp.JspException;
//
import catalog.view.util.FacesUtils;

/**
 * Custom tag implementation class for the SelectedItemRangeValidator.
 * 
 * @author <a href="mailto:derek_shen@hotmail.com">Derek Y. Shen</a>
 * @see SelectedItemsRangeValidator
 */
public class SelectedItemsRangeValidatorTag extends ValidatorTag {
	//the validator id registered in JSF
	private static String VALIDATOR_ID = "catalog.view.validator.SelectedItemsRange";
	
	//the minimum number of items to be selected
	private String minNum;
	
	//the maximum number of items to be selected
	private String maxNum;
	
	/**
	 * Default constructor.
	 */
	public SelectedItemsRangeValidatorTag() {
		this.setValidatorId(VALIDATOR_ID);
	}
	
	public void setMinNum(String newMinNum) {
		this.minNum = newMinNum;
	}
	
	public void setMaxNum(String newMaxNum) {
		this.maxNum = newMaxNum;
	}
	
	/**
	 * Create the validator associated with the tag.
	 * 
	 * @return the validator associated with the tag
	 */
	public Validator createValidator() throws JspException {
		SelectedItemsRangeValidator validator = (SelectedItemsRangeValidator)super.createValidator();
		
		Integer minValue = FacesUtils.evalInt(this.minNum);
		if (minValue != null) {
			validator.setMinNum(minValue.intValue());
		}
		
		Integer maxValue = FacesUtils.evalInt(this.maxNum);
		if (maxValue != null) {
			validator.setMaxNum(maxValue.intValue());
		}
		
		return validator;
	}
	
	public void release() {
		this.minNum = null;
		this.maxNum = null;
	}
}

⌨️ 快捷键说明

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