001/*
002 * Copyright 2002-2013 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.servlet.tags.form;
018
019import javax.servlet.jsp.JspException;
020
021/**
022 * The {@code <hidden>} tag renders an HTML 'input' tag with type 'hidden' using
023 * the bound value.
024 *
025 * <p>Example (binding to 'name' property of form backing object):
026 * <pre class="code">
027 * &lt;form:hidden path=&quot;name&quot;/&gt;
028 * </pre>
029 *
030 * <p>
031 * <table>
032 * <caption>Attribute Summary</caption>
033 * <thead>
034 * <tr>
035 * <th class="colFirst">Attribute</th>
036 * <th class="colOne">Required?</th>
037 * <th class="colOne">Runtime Expression?</th>
038 * <th class="colLast">Description</th>
039 * </tr>
040 * </thead>
041 * <tbody>
042 * <tr class="altColor">
043 * <td><p>htmlEscape</p></td>
044 * <td><p>false</p></td>
045 * <td><p>true</p></td>
046 * <td><p>Enable/disable HTML escaping of rendered values.</p></td>
047 * </tr>
048 * <tr class="rowColor">
049 * <td><p>id</p></td>
050 * <td><p>false</p></td>
051 * <td><p>true</p></td>
052 * <td><p>HTML Standard Attribute</p></td>
053 * </tr>
054 * <tr class="altColor">
055 * <td><p>path</p></td>
056 * <td><p>true</p></td>
057 * <td><p>true</p></td>
058 * <td><p>Path to property for data binding</p></td>
059 * </tr>
060 * </tbody>
061 * </table>
062 *
063 * @author Rob Harrop
064 * @author Juergen Hoeller
065 * @author Rossen Stoyanchev
066 * @since 2.0
067 */
068@SuppressWarnings("serial")
069public class HiddenInputTag extends AbstractHtmlElementTag {
070
071        /**
072         * The name of the '{@code disabled}' attribute.
073         */
074        public static final String DISABLED_ATTRIBUTE = "disabled";
075
076        private boolean disabled;
077
078
079        /**
080         * Set the value of the '{@code disabled}' attribute.
081         * May be a runtime expression.
082         */
083        public void setDisabled(boolean disabled) {
084                this.disabled = disabled;
085        }
086
087        /**
088         * Get the value of the '{@code disabled}' attribute.
089         */
090        public boolean isDisabled() {
091                return this.disabled;
092        }
093
094
095        /**
096         * Flags "type" as an illegal dynamic attribute.
097         */
098        @Override
099        protected boolean isValidDynamicAttribute(String localName, Object value) {
100                return !"type".equals(localName);
101        }
102
103        /**
104         * Writes the HTML '{@code input}' tag to the supplied {@link TagWriter} including the
105         * databound value.
106         * @see #writeDefaultAttributes(TagWriter)
107         * @see #getBoundValue()
108         */
109        @Override
110        protected int writeTagContent(TagWriter tagWriter) throws JspException {
111                tagWriter.startTag("input");
112                writeDefaultAttributes(tagWriter);
113                tagWriter.writeAttribute("type", "hidden");
114                if (isDisabled()) {
115                        tagWriter.writeAttribute(DISABLED_ATTRIBUTE, "disabled");
116                }
117                String value = getDisplayString(getBoundValue(), getPropertyEditor());
118                tagWriter.writeAttribute("value", processFieldValue(getName(), value, "hidden"));
119                tagWriter.endTag();
120                return SKIP_BODY;
121        }
122
123}