KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > faces > taglib > ValidateLengthTag


1 /*
2  * Copyright 1999-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.cocoon.faces.taglib;
17
18 import org.xml.sax.Attributes JavaDoc;
19 import org.xml.sax.SAXException JavaDoc;
20
21 import javax.faces.validator.Validator;
22 import javax.faces.validator.LengthValidator;
23
24 import org.apache.cocoon.faces.FacesUtils;
25
26 /**
27  * @version CVS $Id: ValidateLengthTag.java 53791 2004-10-05 13:16:15Z vgritsenko $
28  */

29 public class ValidateLengthTag extends ValidatorTag {
30
31     private String JavaDoc minimum;
32     private String JavaDoc maximum;
33
34     public void setMaximum(String JavaDoc maximum) {
35         this.maximum = maximum;
36     }
37
38     public void setMinimum(String JavaDoc minimum) {
39         this.minimum = minimum;
40     }
41
42     public int doStartTag(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc atts)
43     throws SAXException JavaDoc {
44         super.setValidatorId("javax.faces.Length");
45         return super.doStartTag(namespaceURI, localName, qName, atts);
46     }
47
48     protected Validator createValidator() {
49         final UIComponentTag tag = FacesUtils.findParentUIComponentTag(this);
50         LengthValidator validator = (LengthValidator) super.createValidator();
51
52         if (maximum != null) {
53             validator.setMaximum(tag.evaluateInteger(maximum));
54         }
55         if (minimum != null) {
56             validator.setMinimum(tag.evaluateInteger(minimum));
57         }
58
59         return validator;
60     }
61
62     public void recycle() {
63         super.recycle();
64         this.minimum = null;
65         this.maximum = null;
66     }
67 }
68
Popular Tags