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

📄 customvalidation.java

📁 IBM RSA下的JSF开发示例
💻 JAVA
字号:
/**
 * 
 */
package pagecode.validation;

import java.util.Date;
import pagecode.PageCodeBase;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;
import javax.faces.component.html.HtmlForm;
import javax.faces.component.html.HtmlOutputText;
import com.ibm.faces.component.html.HtmlCommandExButton;
import com.ibm.faces.component.html.HtmlScriptCollector;
import javax.faces.component.html.HtmlInputText;

/**
 * @author nan
 *
 */
public class CustomValidation extends PageCodeBase {

	protected HtmlForm form1;
	protected HtmlOutputText text5;
	protected HtmlOutputText text6;
	protected HtmlOutputText text2;
	protected HtmlOutputText text1;
	protected HtmlOutputText text19;
	protected HtmlOutputText text20;
	protected HtmlCommandExButton button1;
	protected HtmlScriptCollector scriptCollector1;
	protected HtmlInputText lengthInput;
	protected HtmlOutputText text3;
	protected HtmlInputText rangeInput;
	protected HtmlOutputText text9;
	protected HtmlInputText evenInput;
	protected HtmlOutputText text10;
	protected HtmlInputText start;
	protected HtmlOutputText text11;
	protected HtmlInputText end;
	protected HtmlOutputText text12;
	protected HtmlOutputText text4;
	
	protected HtmlForm getForm1() {
		if (form1 == null) {
			form1 = (HtmlForm) findComponentInRoot("form1");
		}
		return form1;
	}
	
	protected HtmlOutputText getText5() {
		if (text5 == null) {
			text5 = (HtmlOutputText) findComponentInRoot("text5");
		}
		return text5;
	}
	
	protected HtmlOutputText getText6() {
		if (text6 == null) {
			text6 = (HtmlOutputText) findComponentInRoot("text6");
		}
		return text6;
	}
	
	protected HtmlOutputText getText2() {
		if (text2 == null) {
			text2 = (HtmlOutputText) findComponentInRoot("text2");
		}
		return text2;
	}
	
	protected HtmlOutputText getText1() {
		if (text1 == null) {
			text1 = (HtmlOutputText) findComponentInRoot("text1");
		}
		return text1;
	}
	
	protected HtmlOutputText getText19() {
		if (text19 == null) {
			text19 = (HtmlOutputText) findComponentInRoot("text19");
		}
		return text19;
	}
	
	protected HtmlOutputText getText20() {
		if (text20 == null) {
			text20 = (HtmlOutputText) findComponentInRoot("text20");
		}
		return text20;
	}
	
	protected HtmlCommandExButton getButton1() {
		if (button1 == null) {
			button1 = (HtmlCommandExButton) findComponentInRoot("button1");
		}
		return button1;
	}
	
	protected HtmlScriptCollector getScriptCollector1() {
		if (scriptCollector1 == null) {
			scriptCollector1 = (HtmlScriptCollector) findComponentInRoot("scriptCollector1");
		}
		return scriptCollector1;
	}
	
	protected HtmlInputText getLengthInput() {
		if (lengthInput == null) {
			lengthInput = (HtmlInputText) findComponentInRoot("lengthInput");
		}
		return lengthInput;
	}
	
	protected HtmlOutputText getText3() {
		if (text3 == null) {
			text3 = (HtmlOutputText) findComponentInRoot("text3");
		}
		return text3;
	}
	
	protected HtmlInputText getRangeInput() {
		if (rangeInput == null) {
			rangeInput = (HtmlInputText) findComponentInRoot("rangeInput");
		}
		return rangeInput;
	}
	
	protected HtmlOutputText getText9() {
		if (text9 == null) {
			text9 = (HtmlOutputText) findComponentInRoot("text9");
		}
		return text9;
	}
	protected HtmlInputText getEvenInput() {
		if (evenInput == null) {
			evenInput = (HtmlInputText) findComponentInRoot("evenInput");
		}
		return evenInput;
	}
	
	protected HtmlOutputText getText10() {
		if (text10 == null) {
			text10 = (HtmlOutputText) findComponentInRoot("text10");
		}
		return text10;
	}
	
	protected HtmlInputText getStart() {
		if (start == null) {
			start = (HtmlInputText) findComponentInRoot("start");
		}
		return start;
	}
	
	protected HtmlOutputText getText11() {
		if (text11 == null) {
			text11 = (HtmlOutputText) findComponentInRoot("text11");
		}
		return text11;
	}
	
	protected HtmlInputText getEnd() {
		if (end == null) {
			end = (HtmlInputText) findComponentInRoot("end");
		}
		return end;
	}
	
	protected HtmlOutputText getText12() {
		if (text12 == null) {
			text12 = (HtmlOutputText) findComponentInRoot("text12");
		}
		return text12;
	}
	
	protected HtmlOutputText getText4() {
		if (text4 == null) {
			text4 = (HtmlOutputText) findComponentInRoot("text4");
		}
		return text4;
	}
	
	/*
	 * The custom validation method.
	 */
	public void validateDate(FacesContext context, UIComponent component, Object value) {
		// get the date from the first Data Field
		Date startDate = (Date)getStart().getLocalValue();
		
		// get the data passed into this method from the second Date Field
		Date endDate = (Date)value;
		
		if( !endDate.after(startDate)) {
			FacesMessage msg = new FacesMessage("Error: The end date must come after the start date.");
			throw new ValidatorException(msg);
		}
	}
	
}

⌨️ 快捷键说明

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