KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > html > CheckboxTag


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.view.jsp.html;
8
9
10 import java.io.IOException JavaDoc;
11
12 import javax.servlet.jsp.JspException JavaDoc;
13
14 import com.inversoft.verge.mvc.view.HtmlViewToolkit;
15
16
17 /**
18  * This class is the check box input tag.
19  *
20  * @author Brian Pontarelli
21  */

22 public class CheckboxTag extends InputTag {
23
24     private Boolean JavaDoc checked;
25
26
27     /**
28      * Retrieves the tag's checked attribute
29      *
30      * @return The tag's checked attribute
31      */

32     public Boolean JavaDoc getChecked() {
33         return checked;
34     }
35
36     /**
37      * Populates the tag's checked attribute
38      *
39      * @param checked The tag's checked attribute
40      */

41     public void setChecked(Boolean JavaDoc checked) {
42         this.checked = checked;
43     }
44
45     /**
46      * Generate the HTML tag
47      *
48      * @see javax.servlet.jsp.tagext.Tag#doStartTag()
49      */

50     public int doStartTag() throws JspException JavaDoc {
51
52         // Initialize the parent
53
initialize();
54
55         try {
56             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
57             createCheckboxTag(buf, getId(), localName, localValue, checked);
58             pageContext.getOut().print(buf.toString());
59         } catch (IOException JavaDoc ioe) {
60             throw new JspException JavaDoc(ioe.toString());
61         }
62
63         return SKIP_BODY;
64     }
65
66     /**
67      * Does the work of creating the tags body. This method can be overridden
68      * in sub-classes to change the attributes that are appended, etc. By default
69      * this creates a radio tag with the name, value, attributes (single and named)
70      * and NOT checked
71      *
72      * @param checked Determines whether or not this tag is checked or not
73      * @param buf The StringBuffer to append to
74      */

75     protected void createCheckboxTag(StringBuffer JavaDoc buf, String JavaDoc id, String JavaDoc name,
76             Object JavaDoc value, Boolean JavaDoc checked)
77     throws JspException JavaDoc {
78         boolean checkedBool = (checked == null) ? false : checked.booleanValue();
79         String JavaDoc valueStr = (value == null) ? null : value.toString();
80         HtmlViewToolkit.createCheckboxTag(buf, id, name, valueStr, checkedBool,
81             attributes, singleAttrs);
82     }
83 }
Popular Tags