2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to you under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  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  
18  package org.apache.shale.validator.faces;
19  
20  import javax.servlet.jsp.tagext.TagSupport;
21  import javax.servlet.jsp.tagext.Tag;
22  import javax.servlet.jsp.JspException;
23  
24  /***
25   * The tag class for the <code>s:validatorVar</code> tag, used to specify
26   * parameters to specific validators of Commons Validator.
27   * <p/>
28   * $Id: ValidatorVarTag.java 465067 2006-10-17 21:45:17Z rahul $
29   */
30  public class ValidatorVarTag extends TagSupport {
31  
32     /***
33      * Serial version UID.
34      */
35     private static final long serialVersionUID = -7534191231970388638L;
36  
37  
38     /***
39      * The parent validator tag.
40      */
41     private ValidatorTag commonsValidatorTag = null;
42  
43  
44     /***
45      * The name of the var to pass to the validator.
46      */
47     private String name;
48  
49  
50     /***
51      * The value of the var to pass to the validator.
52      */
53     private String value;
54  
55  
56     /***
57      * Keeps track of the &lt;s:commonsValidator&gt; tag.
58      * <p/>
59      *
60      * @param tag the parent tag of this tag instance.
61      */
62     public void setParent(Tag tag) {
63        super.setParent(tag);
64        if (tag instanceof ValidatorTag) {
65           commonsValidatorTag = (ValidatorTag) tag;
66        } else {
67           throw new IllegalStateException(
68                 "This tag must be used inside a <s:commonsValidator> tag");
69        }
70     }
71  
72  
73     /***
74      * Pass the validation parameter to the commonsValidatorTag that immediately
75      * surrounds this tag.
76      *
77      * @exception JspException if a JSP processing error occurs
78      * @return Request to evaluate the page
79      */
80     public int doEndTag() throws JspException {
81        commonsValidatorTag.addParam(name, value);
82        return EVAL_PAGE;
83     }
84  
85  
86     //**************************************************************** Accessors
87  
88  
89     /**
90      * The var name.
91      *
92      * @param name The variable name
93      */
94     public void setName(String name) {
95        this.name = name;
96     }
97  
98  
99     /***
100     * The var value.
101     *
102     * @param value The variable value
103     */
104    public void setValue(String value) {
105       this.value = value;
106    }
107 
108 
109 }