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

📄 expressionlanguage.java

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

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

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

	protected HtmlScriptCollector scriptCollector1;

	protected HtmlForm form1;

	protected HtmlOutputText text14;

	protected HtmlOutputText text3;

	protected HtmlSelectOneMenu menu1;

	protected HtmlOutputText text5;

	protected HtmlInputText text4;

	protected HtmlOutputText text7;

	protected HtmlInputText text8;

	protected HtmlOutputText text15;

	protected HtmlOutputText text1;

	protected HtmlSelectOneMenu menu2;

	protected HtmlOutputText text10;

	protected HtmlInputText text2;

	protected HtmlOutputText text11;

	protected HtmlInputText text12;

	protected HtmlCommandExButton button1;

	protected HtmlOutputText text9;

	protected HtmlScriptCollector getScriptCollector1() {
		if (scriptCollector1 == null) {
			scriptCollector1 = (HtmlScriptCollector) findComponentInRoot("scriptCollector1");
		}
		return scriptCollector1;
	}

	protected HtmlForm getForm1() {
		if (form1 == null) {
			form1 = (HtmlForm) findComponentInRoot("form1");
		}
		return form1;
	}

	protected HtmlOutputText getText14() {
		if (text14 == null) {
			text14 = (HtmlOutputText) findComponentInRoot("text14");
		}
		return text14;
	}

	protected HtmlOutputText getText3() {
		if (text3 == null) {
			text3 = (HtmlOutputText) findComponentInRoot("text3");
		}
		return text3;
	}

	protected HtmlSelectOneMenu getMenu1() {
		if (menu1 == null) {
			menu1 = (HtmlSelectOneMenu) findComponentInRoot("menu1");
		}
		return menu1;
	}

	protected HtmlOutputText getText5() {
		if (text5 == null) {
			text5 = (HtmlOutputText) findComponentInRoot("text5");
		}
		return text5;
	}

	protected HtmlInputText getText4() {
		if (text4 == null) {
			text4 = (HtmlInputText) findComponentInRoot("text4");
		}
		return text4;
	}

	protected HtmlOutputText getText7() {
		if (text7 == null) {
			text7 = (HtmlOutputText) findComponentInRoot("text7");
		}
		return text7;
	}

	protected HtmlInputText getText8() {
		if (text8 == null) {
			text8 = (HtmlInputText) findComponentInRoot("text8");
		}
		return text8;
	}

	protected HtmlOutputText getText15() {
		if (text15 == null) {
			text15 = (HtmlOutputText) findComponentInRoot("text15");
		}
		return text15;
	}

	protected HtmlOutputText getText1() {
		if (text1 == null) {
			text1 = (HtmlOutputText) findComponentInRoot("text1");
		}
		return text1;
	}

	protected HtmlSelectOneMenu getMenu2() {
		if (menu2 == null) {
			menu2 = (HtmlSelectOneMenu) findComponentInRoot("menu2");
		}
		return menu2;
	}

	protected HtmlOutputText getText10() {
		if (text10 == null) {
			text10 = (HtmlOutputText) findComponentInRoot("text10");
		}
		return text10;
	}

	protected HtmlInputText getText2() {
		if (text2 == null) {
			text2 = (HtmlInputText) findComponentInRoot("text2");
		}
		return text2;
	}

	protected HtmlOutputText getText11() {
		if (text11 == null) {
			text11 = (HtmlOutputText) findComponentInRoot("text11");
		}
		return text11;
	}

	protected HtmlInputText getText12() {
		if (text12 == null) {
			text12 = (HtmlInputText) findComponentInRoot("text12");
		}
		return text12;
	}

	protected HtmlCommandExButton getButton1() {
		if (button1 == null) {
			button1 = (HtmlCommandExButton) findComponentInRoot("button1");
		}
		return button1;
	}

	protected HtmlOutputText getText9() {
		if (text9 == null) {
			text9 = (HtmlOutputText) findComponentInRoot("text9");
		}
		return text9;
	}

	public void validateDate(FacesContext context, UIComponent component,
			Object value) {
		boolean valid = false;
		try {
			int day = Integer.parseInt((String) getText4().getLocalValue());
			int month = Integer.parseInt((String) getMenu1().getLocalValue());
			int year = Integer.parseInt((String) value);

			if (month == 2) {
				if (year % 4 == 0 && (year % 400 == 0 || year % 100 != 0)) {
					if (day <= 29) {
						valid = true;
					}
				} else if (day <= 28) {
					valid = true;
				}
			} else if (month == 4 || month == 6 || month == 9 || month == 11) {
				if (day <= 30) {
					valid = true;
				}
			} else {
				if (day <= 31) {
					valid = true;
				}
			}
			if (!valid) {
				FacesMessage msg = new FacesMessage(
						"Error: The Date entered is not valid.");
				throw new ValidatorException(msg);
			}
		} catch (NumberFormatException e) {
			FacesMessage msg = new FacesMessage(
					"Error: Dates must be entered in number format.");
			throw new ValidatorException(msg);
		}
	}

	public void validateReturnDate(FacesContext context, UIComponent component,
			Object value) {
		boolean valid = false;
		try {
			int day = Integer.parseInt((String) getText2().getLocalValue());
			int month = Integer.parseInt((String) getMenu2().getLocalValue());
			int year = Integer.parseInt((String) value);

			if (month == 2) {
				if (year % 4 == 0 && (year % 400 == 0 || year % 100 != 0)) {
					if (day <= 29) {
						valid = true;
					}
				} else if (day <= 28) {
					valid = true;
				}
			} else if (month == 4 || month == 6 || month == 9 || month == 11) {
				if (day <= 30) {
					valid = true;
				}
			} else {
				if (day <= 31) {
					valid = true;
				}
			}
			if (!valid) {
				FacesMessage msg = new FacesMessage(
						"Error: The Date entered is not valid.");
				throw new ValidatorException(msg);
			}
		} catch (NumberFormatException e) {
			FacesMessage msg = new FacesMessage(
					"Error: Dates must be entered in number format.");
			throw new ValidatorException(msg);
		}
	}

}

⌨️ 快捷键说明

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