Chinaunix首页 | 论坛 | 博客
  • 博客访问: 871423
  • 博文数量: 215
  • 博客积分: 10062
  • 博客等级: 上将
  • 技术积分: 2235
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-01 13:21
文章分类

全部博文(215)

文章存档

2012年(1)

2011年(24)

2009年(16)

2008年(91)

2007年(83)

我的朋友

分类:

2007-12-13 22:18:34

自定制验证器代码:
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
下载: 下载

阅读(756) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~