KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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