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

📄 ourvalidator.java

📁 the musiccollection struts 1 application i netbeans implementation (strut for dummies book source)
💻 JAVA
字号:
package dummies.struts.music;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.validator.Field;
import org.apache.commons.validator.GenericValidator;
import org.apache.commons.validator.ValidatorAction;
import org.apache.commons.validator.ValidatorUtil;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.validator.Resources;

/**
 * A custom validator used with the Struts Validator package
 * @author Matt Raible
 */
public class OurValidator
{
	/**
	 * Validator that compares two fields for equality.
	 * @param bean
	 * @param va
	 * @param field
	 * @param errors
	 * @param request
	 * @return boolean
	 */
	public static boolean validateTwoFields( Object bean,
											 ValidatorAction va,
											 Field field,
											 ActionErrors errors,
											 HttpServletRequest request)
	{
		String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
		String sProperty2 = field.getVarValue("secondProperty");
		String value2 = ValidatorUtil.getValueAsString(bean, sProperty2);

		if (!GenericValidator.isBlankOrNull(value))
		{
			try
			{
				if (!value.equals(value2))
				{
					errors.add( field.getKey(),
								Resources.getActionError(request, va, field));
					return false;
				}
			}
			catch (Exception e)
			{
				errors.add( field.getKey(),
							Resources.getActionError(request, va, field));
				return false;
			}
		}

		return true;
	}
}

⌨️ 快捷键说明

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