View Javadoc

1   /*
2    * $Id: HiddenTag.java 471754 2006-11-06 14:55:09Z husted $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.struts.taglib.html;
22  
23  import org.apache.struts.taglib.TagUtils;
24  
25  import javax.servlet.jsp.JspException;
26  
27  /**
28   * Custom tag for input fields of type "hidden".
29   *
30   * @version $Rev: 471754 $ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
31   *          $
32   */
33  public class HiddenTag extends BaseFieldTag {
34      // ------------------------------------------------------------- Properties
35  
36      /**
37       * Should the value of this field also be rendered to the response?
38       */
39      protected boolean write = false;
40  
41      // ----------------------------------------------------------- Constructors
42  
43      /**
44       * Construct a new instance of this tag.
45       */
46      public HiddenTag() {
47          super();
48          this.type = "hidden";
49      }
50  
51      public boolean getWrite() {
52          return (this.write);
53      }
54  
55      public void setWrite(boolean write) {
56          this.write = write;
57      }
58  
59      // --------------------------------------------------------- Public Methods
60  
61      /**
62       * Generate the required input tag, followed by the optional rendered
63       * text. Support for <code>write</code> property since Struts 1.1.
64       *
65       * @throws JspException if a JSP exception has occurred
66       */
67      public int doStartTag() throws JspException {
68          // Render the <html:input type="hidden"> tag as before
69          super.doStartTag();
70  
71          // Is rendering the value separately requested?
72          if (!write) {
73              return (EVAL_BODY_TAG);
74          }
75  
76          // Calculate the value to be rendered separately
77          // * @since Struts 1.1
78          String results = null;
79  
80          if (value != null) {
81              results = TagUtils.getInstance().filter(value);
82          } else {
83              Object value =
84                  TagUtils.getInstance().lookup(pageContext, name, property, null);
85  
86              if (value == null) {
87                  results = "";
88              } else {
89                  results = TagUtils.getInstance().filter(value.toString());
90              }
91          }
92  
93          TagUtils.getInstance().write(pageContext, results);
94  
95          return (EVAL_BODY_TAG);
96      }
97  
98      /**
99       * Release any acquired resources.
100      */
101     public void release() {
102         super.release();
103         write = false;
104     }
105 }