KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > custom > regexprvalidator > ValidateRegExprTag


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.custom.regexprvalidator;
17
18 import javax.faces.context.FacesContext;
19 import javax.faces.el.ValueBinding;
20 import javax.faces.validator.Validator;
21 import javax.faces.webapp.UIComponentTag;
22 import javax.faces.webapp.ValidatorTag;
23 import javax.servlet.jsp.JspException JavaDoc;
24
25 /**
26  * @author mwessendorf (latest modification by $Author: matze $)
27  * @version $Revision: 1.5 $ $Date: 2004/10/13 11:50:57 $
28  * $Log: ValidateRegExprTag.java,v $
29  * Revision 1.5 2004/10/13 11:50:57 matze
30  * renamed packages to org.apache
31  *
32  * Revision 1.4 2004/09/15 07:58:59 mwessendorf
33  * Custom Validators now work in OC4J - thanks to Daniel Kamakura for supporting this
34  *
35  * Revision 1.3 2004/07/01 21:53:11 mwessendorf
36  * ASF switch
37  *
38  * Revision 1.2 2004/06/27 22:06:27 mwessendorf
39  * Log
40  *
41  *
42  */

43 public class ValidateRegExprTag extends ValidatorTag {
44     
45     //the pattern, needed by Commons-Validator.
46
private String JavaDoc _pattern = null;
47     
48     public ValidateRegExprTag(){
49     }
50
51     public void setPattern(String JavaDoc string) {
52         _pattern = string;
53     }
54
55     protected Validator createValidator() throws JspException JavaDoc {
56
57         FacesContext facesContext = FacesContext.getCurrentInstance();
58         setValidatorId(RegExprValidator.VALIDATOR_ID);
59         RegExprValidator validator = (RegExprValidator)super.createValidator();
60         if (_pattern != null)
61         {
62             if (UIComponentTag.isValueReference(_pattern))
63             {
64                 ValueBinding vb = facesContext.getApplication().createValueBinding(_pattern);
65                 validator.setPattern(new String JavaDoc(vb.getValue(facesContext).toString()));
66             }
67             else
68             {
69                 validator.setPattern(_pattern);
70             }
71         }
72         return validator;
73     }
74     public void release()
75     {
76         super.release();
77        _pattern= null;
78     }
79
80 }
81
Popular Tags