001: /*
002: * $Id: HiddenTag.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts.taglib.html;
022:
023: import org.apache.struts.taglib.TagUtils;
024:
025: import javax.servlet.jsp.JspException;
026:
027: /**
028: * Custom tag for input fields of type "hidden".
029: *
030: * @version $Rev: 471754 $ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
031: * $
032: */
033: public class HiddenTag extends BaseFieldTag {
034: // ------------------------------------------------------------- Properties
035:
036: /**
037: * Should the value of this field also be rendered to the response?
038: */
039: protected boolean write = false;
040:
041: // ----------------------------------------------------------- Constructors
042:
043: /**
044: * Construct a new instance of this tag.
045: */
046: public HiddenTag() {
047: super ();
048: this .type = "hidden";
049: }
050:
051: public boolean getWrite() {
052: return (this .write);
053: }
054:
055: public void setWrite(boolean write) {
056: this .write = write;
057: }
058:
059: // --------------------------------------------------------- Public Methods
060:
061: /**
062: * Generate the required input tag, followed by the optional rendered
063: * text. Support for <code>write</code> property since Struts 1.1.
064: *
065: * @throws JspException if a JSP exception has occurred
066: */
067: public int doStartTag() throws JspException {
068: // Render the <html:input type="hidden"> tag as before
069: super .doStartTag();
070:
071: // Is rendering the value separately requested?
072: if (!write) {
073: return (EVAL_BODY_TAG);
074: }
075:
076: // Calculate the value to be rendered separately
077: // * @since Struts 1.1
078: String results = null;
079:
080: if (value != null) {
081: results = TagUtils.getInstance().filter(value);
082: } else {
083: Object value = TagUtils.getInstance().lookup(pageContext,
084: name, property, null);
085:
086: if (value == null) {
087: results = "";
088: } else {
089: results = TagUtils.getInstance().filter(
090: value.toString());
091: }
092: }
093:
094: TagUtils.getInstance().write(pageContext, results);
095:
096: return (EVAL_BODY_TAG);
097: }
098:
099: /**
100: * Release any acquired resources.
101: */
102: public void release() {
103: super .release();
104: write = false;
105: }
106: }
|