KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > taglib > html > HiddenTag


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

18
19 package org.apache.struts.taglib.html;
20
21 import javax.servlet.jsp.JspException JavaDoc;
22
23 import org.apache.struts.taglib.TagUtils;
24
25 /**
26  * Custom tag for input fields of type "hidden".
27  *
28  * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
29  */

30 public class HiddenTag extends BaseFieldTag {
31
32
33     // ----------------------------------------------------------- Constructors
34

35     /**
36      * Construct a new instance of this tag.
37      */

38     public HiddenTag() {
39
40     super();
41     this.type = "hidden";
42
43     }
44
45
46     // ------------------------------------------------------------- Properties
47

48
49     /**
50      * Should the value of this field also be rendered to the response?
51      */

52     protected boolean write = false;
53
54     public boolean getWrite() {
55         return (this.write);
56     }
57
58     public void setWrite(boolean write) {
59         this.write = write;
60     }
61
62
63     // --------------------------------------------------------- Public Methods
64

65
66     /**
67      * Generate the required input tag, followed by the optional rendered text.
68      * Support for <code>write</code> property since Struts 1.1.
69      *
70      * @exception JspException if a JSP exception has occurred
71      */

72     public int doStartTag() throws JspException JavaDoc {
73
74         // Render the <html:input type="hidden"> tag as before
75
super.doStartTag();
76
77         // Is rendering the value separately requested?
78
if (!write) {
79             return (EVAL_BODY_TAG);
80         }
81
82
83         // Calculate the value to be rendered separately
84
// * @since Struts 1.1
85
String JavaDoc results = null;
86         if (value != null) {
87             results = TagUtils.getInstance().filter(value);
88         } else {
89             Object JavaDoc value = TagUtils.getInstance().lookup(pageContext, name, property,
90                                                null);
91             if (value == null) {
92                 results = "";
93             } else {
94                 results = TagUtils.getInstance().filter(value.toString());
95             }
96         }
97
98         TagUtils.getInstance().write(pageContext, results);
99         return (EVAL_BODY_TAG);
100
101     }
102
103
104     /**
105      * Release any acquired resources.
106      */

107     public void release() {
108
109         super.release();
110         write = false;
111
112     }
113
114
115 }
116
Popular Tags