001/*
002 * Copyright 2002-2018 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 <radiobutton>} tag renders an HTML 'input' tag with type 'radio'.
023 *
024 * <p>Rendered elements are marked as 'checked' if the configured
025 * {@link #setValue(Object) value} matches the {@link #getValue bound value}.
026 *
027 * <p>A typical usage pattern will involved multiple tag instances bound
028 * to the same property but with different values.
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>accesskey</p></td>
044 * <td><p>false</p></td>
045 * <td><p>true</p></td>
046 * <td><p>HTML Standard Attribute</p></td>
047 * </tr>
048 * <tr class="rowColor">
049 * <td><p>cssClass</p></td>
050 * <td><p>false</p></td>
051 * <td><p>true</p></td>
052 * <td><p>HTML Optional Attribute</p></td>
053 * </tr>
054 * <tr class="altColor">
055 * <td><p>cssErrorClass</p></td>
056 * <td><p>false</p></td>
057 * <td><p>true</p></td>
058 * <td><p>HTML Optional Attribute. Used when the bound field has errors.</p></td>
059 * </tr>
060 * <tr class="rowColor">
061 * <td><p>cssStyle</p></td>
062 * <td><p>false</p></td>
063 * <td><p>true</p></td>
064 * <td><p>HTML Optional Attribute</p></td>
065 * </tr>
066 * <tr class="altColor">
067 * <td><p>dir</p></td>
068 * <td><p>false</p></td>
069 * <td><p>true</p></td>
070 * <td><p>HTML Standard Attribute</p></td>
071 * </tr>
072 * <tr class="rowColor">
073 * <td><p>disabled</p></td>
074 * <td><p>false</p></td>
075 * <td><p>true</p></td>
076 * <td><p>HTML Optional Attribute. Setting the value of this attribute to 'true'
077 * will disable the HTML element.</p></td>
078 * </tr>
079 * <tr class="altColor">
080 * <td><p>htmlEscape</p></td>
081 * <td><p>false</p></td>
082 * <td><p>true</p></td>
083 * <td><p>Enable/disable HTML escaping of rendered values.</p></td>
084 * </tr>
085 * <tr class="rowColor">
086 * <td><p>id</p></td>
087 * <td><p>false</p></td>
088 * <td><p>true</p></td>
089 * <td><p>HTML Standard Attribute</p></td>
090 * </tr>
091 * <tr class="altColor">
092 * <td><p>label</p></td>
093 * <td><p>false</p></td>
094 * <td><p>true</p></td>
095 * <td><p>Value to be displayed as part of the tag</p></td>
096 * </tr>
097 * <tr class="rowColor">
098 * <td><p>lang</p></td>
099 * <td><p>false</p></td>
100 * <td><p>true</p></td>
101 * <td><p>HTML Standard Attribute</p></td>
102 * </tr>
103 * <tr class="altColor">
104 * <td><p>onblur</p></td>
105 * <td><p>false</p></td>
106 * <td><p>true</p></td>
107 * <td><p>HTML Event Attribute</p></td>
108 * </tr>
109 * <tr class="rowColor">
110 * <td><p>onchange</p></td>
111 * <td><p>false</p></td>
112 * <td><p>true</p></td>
113 * <td><p>HTML Event Attribute</p></td>
114 * </tr>
115 * <tr class="altColor">
116 * <td><p>onclick</p></td>
117 * <td><p>false</p></td>
118 * <td><p>true</p></td>
119 * <td><p>HTML Event Attribute</p></td>
120 * </tr>
121 * <tr class="rowColor">
122 * <td><p>ondblclick</p></td>
123 * <td><p>false</p></td>
124 * <td><p>true</p></td>
125 * <td><p>HTML Event Attribute</p></td>
126 * </tr>
127 * <tr class="altColor">
128 * <td><p>onfocus</p></td>
129 * <td><p>false</p></td>
130 * <td><p>true</p></td>
131 * <td><p>HTML Event Attribute</p></td>
132 * </tr>
133 * <tr class="rowColor">
134 * <td><p>onkeydown</p></td>
135 * <td><p>false</p></td>
136 * <td><p>true</p></td>
137 * <td><p>HTML Event Attribute</p></td>
138 * </tr>
139 * <tr class="altColor">
140 * <td><p>onkeypress</p></td>
141 * <td><p>false</p></td>
142 * <td><p>true</p></td>
143 * <td><p>HTML Event Attribute</p></td>
144 * </tr>
145 * <tr class="rowColor">
146 * <td><p>onkeyup</p></td>
147 * <td><p>false</p></td>
148 * <td><p>true</p></td>
149 * <td><p>HTML Event Attribute</p></td>
150 * </tr>
151 * <tr class="altColor">
152 * <td><p>onmousedown</p></td>
153 * <td><p>false</p></td>
154 * <td><p>true</p></td>
155 * <td><p>HTML Event Attribute</p></td>
156 * </tr>
157 * <tr class="rowColor">
158 * <td><p>onmousemove</p></td>
159 * <td><p>false</p></td>
160 * <td><p>true</p></td>
161 * <td><p>HTML Event Attribute</p></td>
162 * </tr>
163 * <tr class="altColor">
164 * <td><p>onmouseout</p></td>
165 * <td><p>false</p></td>
166 * <td><p>true</p></td>
167 * <td><p>HTML Event Attribute</p></td>
168 * </tr>
169 * <tr class="rowColor">
170 * <td><p>onmouseover</p></td>
171 * <td><p>false</p></td>
172 * <td><p>true</p></td>
173 * <td><p>HTML Event Attribute</p></td>
174 * </tr>
175 * <tr class="altColor">
176 * <td><p>onmouseup</p></td>
177 * <td><p>false</p></td>
178 * <td><p>true</p></td>
179 * <td><p>HTML Event Attribute</p></td>
180 * </tr>
181 * <tr class="rowColor">
182 * <td><p>path</p></td>
183 * <td><p>true</p></td>
184 * <td><p>true</p></td>
185 * <td><p>Path to property for data binding</p></td>
186 * </tr>
187 * <tr class="altColor">
188 * <td><p>tabindex</p></td>
189 * <td><p>false</p></td>
190 * <td><p>true</p></td>
191 * <td><p>HTML Standard Attribute</p></td>
192 * </tr>
193 * <tr class="rowColor">
194 * <td><p>title</p></td>
195 * <td><p>false</p></td>
196 * <td><p>true</p></td>
197 * <td><p>HTML Standard Attribute</p></td>
198 * </tr>
199 * <tr class="altColor">
200 * <td><p>value</p></td>
201 * <td><p>false</p></td>
202 * <td><p>true</p></td>
203 * <td><p>HTML Optional Attribute</p></td>
204 * </tr>
205 * </tbody>
206 * </table>
207 *
208 * @author Rob Harrop
209 * @author Juergen Hoeller
210 * @since 2.0
211 */
212@SuppressWarnings("serial")
213public class RadioButtonTag extends AbstractSingleCheckedElementTag {
214
215        @Override
216        protected void writeTagDetails(TagWriter tagWriter) throws JspException {
217                tagWriter.writeAttribute("type", getInputType());
218                Object resolvedValue = evaluate("value", getValue());
219                renderFromValue(resolvedValue, tagWriter);
220        }
221
222        @Override
223        protected String getInputType() {
224                return "radio";
225        }
226
227}