<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    soufan

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      22 隨筆 :: 0 文章 :: 0 評論 :: 0 Trackbacks
    (轉)
    下面是一個email驗證器的示例: ?

    EmailValidator.java:

    import?javax.faces.application.FacesMessage;
    import?javax.faces.component.UIComponent;
    import?javax.faces.context.FacesContext;
    import?javax.faces.validator.Validator;
    import?javax.faces.validator.ValidatorException;
    ?
    public?class?EmailValidator?implements?Validator?{
    ?
    ????private?String?errorMessage?=?null;
    ?
    ????public?void?setErrorMessage(String?errorMessage)?{?this.errorMessage?=?errorMessage;?}
    ?
    ????public?void?validate(FacesContext?context,?UIComponent?component,?Object?value)?{
    ????????if?(null?==?value)?{
    ????????????return;
    ????????}
    ?
    ????????String?email?=?(String)?value;
    ?
    ????????if?(-1?==?email.indexOf('@',?1)?||?-1?==?email.indexOf('.'))?{
    ????????????if?(errorMessage?!=?null)?{
    ????????????????throw?new?ValidatorException(new?FacesMessage(Tags.eval(errorMessage)));
    ????????????}?else?{
    ????????????????//?use?default?validator?message
    ????????????????throw?new?ValidatorException(null);
    ????????????}
    ????????}
    ????}
    }

    Tags.java:

    import?javax.faces.application.Application;
    import?javax.faces.component.UIComponent;
    import?javax.faces.component.UIInput;
    import?javax.faces.context.FacesContext;
    import?javax.faces.el.MethodBinding;
    import?javax.faces.el.ValueBinding;
    import?javax.faces.event.ValueChangeEvent;
    import?javax.faces.webapp.ConverterTag;
    import?javax.faces.webapp.UIComponentTag;
    ?
    public?class?Tags?{
    ???//?Converter?Tags?and?Validator?Tags?helper?methods
    ????public?static?String?eval(String?expression)?{
    ????????if?(expression?!=?null?&&?UIComponentTag.isValueReference(expression))?{
    ????????????FacesContext?context?=?FacesContext.getCurrentInstance();
    ????????????Application?app?=?context.getApplication();
    ????????????ValueBinding?vb?=?app.createValueBinding(expression);
    ????????????return?""?+?vb.getValue(context);
    ????????}?else?{
    ????????????return?expression;
    ????????}
    ????}
    }

    ?

    ?

    ?

    EmailValidatorTag.java:

    import?javax.faces.component.UIComponent;
    import?javax.faces.validator.Validator;
    import?javax.faces.webapp.ValidatorTag;
    import?javax.servlet.jsp.JspException;
    ?
    public?class?EmailValidatorTag?extends?ValidatorTag?{
    ?
    ????private?String?errorMessage?=?null;
    ?
    ????public?EmailValidatorTag()?{
    ????????setValidatorId("Email");
    ????}
    ?
    ????public?void?setErrorMessage(String?errorMessage)?{?this.errorMessage?=?errorMessage;?}
    ?
    ????public?Validator?createValidator()?throws?JspException?{
    ????????EmailValidator?validator?=?(EmailValidator)?super.createValidator();
    ????????validator.setErrorMessage(errorMessage);
    ?
    ????????return?validator;
    ????}
    ?
    ????public?void?release()?{
    ????????errorMessage?=?null;
    ????}
    }

    ?

    ?

    faces-config.xml:

    <validator>
        <validator-id>Email</validator-id>
        <validator-class>EmailValidator</validator-class>
    </validator>
    

    mytags.tld:

    <?xml version="1.0" encoding="UTF-8"?>
     
    <!DOCTYPE taglib PUBLIC
        "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
        "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
     
    <taglib>
     
    <tlibversion>1.0</tlibversion>
    <jspversion>1.2</jspversion>
    <shortname>mytags</shortname>
    <uri>mytags</uri>
     
    <tag>
        <name>validateEmail</name>
        <tagclass>EmailValidatorTag</tagclass>
     
        <attribute>
            <name>errorMessage</name>
            <description>message if a validation error occurs</description>
        </attribute>
    </tag>
     
    </taglib>
    

    ?

    mypage.jsp:

    <h:inputText id="email" required="true">
        <mytags:validateEmail errorMessage="#{bean.message}"/>
    </h:inputText>
    
    posted on 2006-12-19 16:02 soufan 閱讀(236) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 久久午夜免费视频| 免费观看国产网址你懂的| 免费a级毛片在线观看| 亚洲一区二区三区高清在线观看| 99ee6热久久免费精品6| 亚洲成A人片在线观看无码不卡 | 特a级免费高清黄色片| 最近2019中文免费字幕| 亚洲综合丁香婷婷六月香| 无人在线观看完整免费版视频| 亚洲男人天堂2018av| 免费精品一区二区三区在线观看 | 四虎影视www四虎免费| 国产精品亚洲精品久久精品| 免费a级毛片网站| 国产精品美女久久久免费| 亚洲午夜福利717| 精品国产污污免费网站aⅴ| 亚洲婷婷综合色高清在线| 成人在线免费观看| 人成午夜免费大片在线观看| 亚洲啪啪AV无码片| 国产精品久久免费| 色五月五月丁香亚洲综合网| 亚洲无人区一区二区三区| 8x8x华人永久免费视频| 亚洲日本VA中文字幕久久道具| 亚洲国产精品国产自在在线| 日本在线看片免费| 亚洲日韩一区二区一无码| 国产成人综合亚洲亚洲国产第一页| 一区二区三区福利视频免费观看| 亚洲综合一区二区三区四区五区| 日本免费人成视频播放 | 中文字幕在线免费| 亚洲av成人一区二区三区观看在线 | eeuss影院免费92242部| 亚洲高清在线mv| 日韩亚洲精品福利| xxxx日本免费| 国产又黄又爽胸又大免费视频|