KickJava   Java API By Example, From Geeks To Geeks.

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


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.LongRangeValidator;
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 ValidateLongRangeTag
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.LongRange";
40
41     public void release()
42     {
43         super.release();
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         LongRangeValidator validator = (LongRangeValidator)super.createValidator();
64         if (_minimum != null)
65         {
66             if (UIComponentTag.isValueReference(_minimum))
67             {
68                 ValueBinding vb = facesContext.getApplication().createValueBinding(_minimum);
69                 validator.setMinimum(ConverterUtils.convertToLong(vb.getValue(facesContext)));
70             }
71             else
72             {
73                 validator.setMinimum(ConverterUtils.convertToLong(_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.convertToLong(vb.getValue(facesContext)));
82             }
83             else
84             {
85                 validator.setMaximum(ConverterUtils.convertToLong(_maximum));
86             }
87         }
88         return validator;
89     }
90
91
92 }
93
Popular Tags