KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > taglib > core > ValidateLengthTag


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.taglib.core;
17
18 import org.apache.myfaces.convert.ConverterUtils;
19
20 import javax.faces.context.FacesContext;
21 import javax.faces.el.ValueBinding;
22 import javax.faces.validator.LengthValidator;
23 import javax.faces.validator.Validator;
24 import javax.faces.webapp.UIComponentTag;
25 import javax.faces.webapp.ValidatorTag;
26 import javax.servlet.jsp.JspException JavaDoc;
27
28 /**
29  * @author Thomas Spiegl (latest modification by $Author: matze $)
30  * @author Manfred Geiler
31  * @version $Revision: 1.11 $ $Date: 2004/10/13 11:51:00 $
32  */

33 public class ValidateLengthTag
34     extends ValidatorTag
35 {
36     private String JavaDoc _minimum = null;
37     private String JavaDoc _maximum = null;
38
39     private static final String JavaDoc VALIDATOR_ID = "javax.faces.Length";
40
41     public void release()
42     {
43         _minimum = null;
44         _maximum = null;
45     }
46
47     public void setMinimum(String JavaDoc minimum)
48     {
49         _minimum = minimum;
50     }
51
52     public void setMaximum(String JavaDoc maximum)
53     {
54         _maximum = maximum;
55     }
56
57     protected Validator createValidator()
58         throws JspException JavaDoc
59     {
60         FacesContext facesContext = FacesContext.getCurrentInstance();
61         setValidatorId(VALIDATOR_ID);
62         LengthValidator validator = (LengthValidator)super.createValidator();
63         if (_minimum != null)
64         {
65             if (UIComponentTag.isValueReference(_minimum))
66             {
67                 ValueBinding vb = facesContext.getApplication().createValueBinding(_minimum);
68                 validator.setMinimum(ConverterUtils.convertToInt(vb.getValue(facesContext)));
69             }
70             else
71             {
72                 validator.setMinimum(ConverterUtils.convertToInt(_minimum));
73             }
74         }
75         if (_maximum != null)
76         {
77             if (UIComponentTag.isValueReference(_maximum))
78             {
79                 ValueBinding vb = facesContext.getApplication().createValueBinding(_maximum);
80                 validator.setMaximum(ConverterUtils.convertToInt(vb.getValue(facesContext)));
81             }
82             else
83             {
84                 validator.setMaximum(ConverterUtils.convertToInt(_maximum));
85             }
86         }
87         return validator;
88     }
89
90
91 }
92
Popular Tags