1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts2.components;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22
23 import com.opensymphony.xwork2.util.ValueStack;
24
25 /***
26 * <!-- START SNIPPET: javadoc -->
27 * Renders an HTML input element of type checkbox, populated by the specified property from the ValueStack.
28 * <!-- END SNIPPET: javadoc -->
29 *
30 * <p/> <b>Examples</b>
31 *
32 * <pre>
33 * <!-- START SNIPPET: example -->
34 * JSP:
35 * <s:checkbox label="checkbox test" name="checkboxField1" value="aBoolean" fieldValue="true"/>
36 *
37 * Velocity:
38 * #tag( Checkbox "label=checkbox test" "name=checkboxField1" "value=aBoolean" )
39 *
40 * Resulting HTML (simple template, aBoolean == true):
41 * <input type="checkbox" name="checkboxField1" value="true" checked="checked" />
42 *
43 * <!-- END SNIPPET: example -->
44 * </pre>
45 *
46 * @s.tag name="checkbox" tld-body-content="JSP" tld-tag-class="org.apache.struts2.views.jsp.ui.CheckboxTag"
47 * description="Render a checkbox input field"
48 */
49 public class Checkbox extends UIBean {
50 final public static String TEMPLATE = "checkbox";
51
52 protected String fieldValue;
53
54 public Checkbox(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
55 super(stack, request, response);
56 }
57
58 protected String getDefaultTemplate() {
59 return TEMPLATE;
60 }
61
62 protected void evaluateExtraParams() {
63 if (fieldValue != null) {
64 addParameter("fieldValue", findString(fieldValue));
65 } else {
66 addParameter("fieldValue", "true");
67 }
68 }
69
70 protected Class getValueClassType() {
71 return Boolean.class;
72 }
73
74 /***
75 * The actual HTML value attribute of the checkbox.
76 * @s.tagattribute required="false" default="'true'"
77 */
78 public void setFieldValue(String fieldValue) {
79 this.fieldValue = fieldValue;
80 }
81
82 }