自定制验证器代码:
package com.itanger.jane.web;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
public class OneToTenValidator implements Validator {
public OneToTenValidator() {
}
public void validate(FacesContext facesContext, UIComponent uIComponent,
Object object) throws ValidatorException {
boolean Valid = false;
String value = null;
int i;
if (!(uIComponent instanceof UIInput) || (object == null)) {
return;
}
value = object.toString();
try {
i = Integer.parseInt(value);
} catch (NumberFormatException exe) {
FacesMessage message = new FacesMessage("不能成功的转化");
throw new ValidatorException(message);
}
if ((i < 1) || (i > 10)) {
FacesMessage message = new FacesMessage("数值应该在1到10之间");
throw new ValidatorException(message);
}
return;
}
}
//本例源代码中还有相关事件的用法:
|
文件: |
SelfValidator.rar |
大小: |
1988KB |
下载: |
下载 | |
阅读(791) | 评论(0) | 转发(0) |