01: package com.opensymphony.webwork.components;
02:
03: import com.opensymphony.xwork.util.OgnlValueStack;
04:
05: import javax.servlet.http.HttpServletRequest;
06: import javax.servlet.http.HttpServletResponse;
07:
08: /**
09: * <!-- START SNIPPET: javadoc -->
10: * Renders an HTML input element of type checkbox, populated by the specified property from the OgnlValueStack.
11: * <!-- END SNIPPET: javadoc -->
12: *
13: * <p/> <b>Examples</b>
14: *
15: * <pre>
16: * <!-- START SNIPPET: example -->
17: * JSP:
18: * <ww:checkbox label="checkbox test" name="checkboxField1" value="aBoolean" fieldValue="true"/>
19: *
20: * Velocity:
21: * #tag( Checkbox "label=checkbox test" "name=checkboxField1" "value=aBoolean" )
22: *
23: * Resulting HTML (simple template, aBoolean == true):
24: * <input type="checkbox" name="checkboxField1" value="true" checked="checked" />
25: *
26: * <!-- END SNIPPET: example -->
27: * </pre>
28: *
29: * @author Patrick Lightbody
30: * @author Rene Gielen
31: * @version $Revision: 2468 $
32: * @since 2.2
33: *
34: * @ww.tag name="checkbox" tld-body-content="JSP" tld-tag-class="com.opensymphony.webwork.views.jsp.ui.CheckboxTag"
35: * description="Render a checkbox input field"
36: */
37: public class Checkbox extends UIBean {
38: final public static String TEMPLATE = "checkbox";
39:
40: protected String fieldValue;
41:
42: public Checkbox(OgnlValueStack stack, HttpServletRequest request,
43: HttpServletResponse response) {
44: super (stack, request, response);
45: }
46:
47: protected String getDefaultTemplate() {
48: return TEMPLATE;
49: }
50:
51: protected void evaluateExtraParams() {
52: if (fieldValue != null) {
53: addParameter("fieldValue", findString(fieldValue));
54: } else {
55: addParameter("fieldValue", "true");
56: }
57: }
58:
59: protected Class getValueClassType() {
60: return Boolean.class; // for checkboxes, everything needs to end up as a Boolean
61: }
62:
63: /**
64: * The actual HTML value attribute of the checkbox.
65: * @ww.tagattribute required="false" default="'true'"
66: */
67: public void setFieldValue(String fieldValue) {
68: this.fieldValue = fieldValue;
69: }
70:
71: }
|