KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > custom > equalvalidator > ValidateEqualTag


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.equalvalidator;
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.6 $ $Date: 2004/10/13 11:50:57 $
28  * $Log: ValidateEqualTag.java,v $
29  * Revision 1.6 2004/10/13 11:50:57 matze
30  * renamed packages to org.apache
31  *
32  * Revision 1.5 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.4 2004/07/11 16:20:21 mwessendorf
36  * typo
37  *
38  * Revision 1.3 2004/07/01 21:53:10 mwessendorf
39  * ASF switch
40  *
41  * Revision 1.2 2004/06/27 22:06:27 mwessendorf
42  * Log
43  *
44  *
45  */

46 public class ValidateEqualTag extends ValidatorTag {
47     
48     //the foreign component_id on which the validation is based.
49
private String JavaDoc _for = null;
50     
51     public ValidateEqualTag(){
52     }
53
54     public void setFor(String JavaDoc string) {
55         _for = string;
56     }
57
58     protected Validator createValidator() throws JspException JavaDoc {
59
60         FacesContext facesContext = FacesContext.getCurrentInstance();
61         setValidatorId(EqualValidator.VALIDATOR_ID);
62         EqualValidator validator = (EqualValidator)super.createValidator();
63         if (_for != null)
64         {
65             if (UIComponentTag.isValueReference(_for))
66             {
67                 ValueBinding vb = facesContext.getApplication().createValueBinding(_for);
68                 validator.setFor(new String JavaDoc(vb.getValue(facesContext).toString()));
69             }
70             else
71             {
72                 validator.setFor(_for);
73             }
74         }
75         return validator;
76     }
77     public void release() {
78         super.release();
79        _for = null;
80     }
81 }
82
Popular Tags