⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 selecteditemsrangevalidator.java

📁 一个ssh结构组成 的BS开发
💻 JAVA
字号:
package cn.hxex.library.view.validator;

import java.util.List;

import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

public class SelectedItemsRangeValidator implements Validator
{
	// the minimum number of the items to be selected
	private int minNum = Integer.MIN_VALUE;

	// the maximum number of the items to be selected
	private int maxNum = Integer.MAX_VALUE;

	/**
	 * Main method to implement for <code>Validator</code>
	 */
	public void validate(FacesContext context, UIComponent component,
			Object value)
	{
		if (value == null)
		{
			return;
		}

		List valueList = null;

		try
		{
			valueList = (List) value;
		} catch (Exception e)
		{
			throw new FacesException(
					"UISelectManyValidator can only be attached to component UISelectMany.");
		}

		String msg = null;

		if (valueList.size() < this.minNum)
		{
			msg = "At least " + this.minNum + " items should be selected.";
		} else if (valueList.size() > this.maxNum)
		{
			msg = "At most " + this.maxNum + " items should be selected.";
		}

		if (msg != null)
		{
			FacesMessage message = new FacesMessage(
					FacesMessage.SEVERITY_ERROR, msg, msg);
			throw new ValidatorException(message);
		}
	}

	public void setMinNum(int newMinNum)
	{
		this.minNum = newMinNum;
	}

	public void setMaxNum(int newMaxNum)
	{
		this.maxNum = newMaxNum;
	}
}

⌨️ 快捷键说明

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