View Javadoc

1   /*
2    * $Id: HiddenTag.java 376841 2006-02-10 21:01:28Z husted $
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  package org.apache.struts.taglib.html;
19  
20  import org.apache.struts.taglib.TagUtils;
21  
22  import javax.servlet.jsp.JspException;
23  
24  /***
25   * Custom tag for input fields of type "hidden".
26   *
27   * @version $Rev: 376841 $ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
28   *          $
29   */
30  public class HiddenTag extends BaseFieldTag {
31      // ------------------------------------------------------------- Properties
32  
33      /***
34       * Should the value of this field also be rendered to the response?
35       */
36      protected boolean write = false;
37  
38      // ----------------------------------------------------------- Constructors
39  
40      /***
41       * Construct a new instance of this tag.
42       */
43      public HiddenTag() {
44          super();
45          this.type = "hidden";
46      }
47  
48      public boolean getWrite() {
49          return (this.write);
50      }
51  
52      public void setWrite(boolean write) {
53          this.write = write;
54      }
55  
56      // --------------------------------------------------------- Public Methods
57  
58      /***
59       * Generate the required input tag, followed by the optional rendered
60       * text. Support for <code>write</code> property since Struts 1.1.
61       *
62       * @throws JspException if a JSP exception has occurred
63       */
64      public int doStartTag() throws JspException {
65          // Render the <html:input type="hidden"> tag as before
66          super.doStartTag();
67  
68          // Is rendering the value separately requested?
69          if (!write) {
70              return (EVAL_BODY_TAG);
71          }
72  
73          // Calculate the value to be rendered separately
74          // * @since Struts 1.1
75          String results = null;
76  
77          if (value != null) {
78              results = TagUtils.getInstance().filter(value);
79          } else {
80              Object value =
81                  TagUtils.getInstance().lookup(pageContext, name, property, null);
82  
83              if (value == null) {
84                  results = "";
85              } else {
86                  results = TagUtils.getInstance().filter(value.toString());
87              }
88          }
89  
90          TagUtils.getInstance().write(pageContext, results);
91  
92          return (EVAL_BODY_TAG);
93      }
94  
95      /***
96       * Release any acquired resources.
97       */
98      public void release() {
99          super.release();
100         write = false;
101     }
102 }