KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.log4j.Logger;
15
16 import com.inversoft.util.ObjectTools;
17 import com.inversoft.verge.mvc.view.HtmlViewToolkit;
18
19
20 /**
21  * This class is the radio box input tag.
22  *
23  * @author Brian Pontarelli
24  */

25 public class RadioTag extends InputTag {
26
27     /**
28      * This classes logger
29      */

30     private static final Logger logger = Logger.getLogger(RadioTag.class);
31
32     private Boolean JavaDoc checked;
33
34
35     /**
36      * Retrieves the tag's checked attribute
37      *
38      * @return The tag's checked attribute
39      */

40     public Boolean JavaDoc getChecked() {
41         return checked;
42     }
43
44     /**
45      * Populates the tag's checked attribute
46      *
47      * @param checked The tag's checked attribute
48      */

49     public void setChecked(Boolean JavaDoc checked) {
50         this.checked = checked;
51     }
52
53     /**
54      * Generate the HTML tag
55      */

56     public int doStartTag() throws JspException JavaDoc {
57
58         // Initialize the parent and the bean property
59
initialize();
60
61         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
62         createRadioTag(buf, getId(), localName, localValue, checked);
63         if (logger.isDebugEnabled()) {
64             logger.debug("The radio tag: " + buf.toString());
65         }
66
67         try {
68             pageContext.getOut().print(buf.toString());
69         } catch (IOException JavaDoc ioe) {
70             throw new JspException JavaDoc(ioe.toString());
71         }
72
73         return SKIP_BODY;
74     }
75
76     /**
77      * Does the work of creating the tags body. This method can be overridden
78      * in sub-classes to change the attributes that are appended, etc. By default
79      * this creates a radio tag with the name, value, attributes (single and named)
80      * and NOT checked
81      *
82      * @param buf The StringBuffer to append to
83      */

84     protected void createRadioTag(StringBuffer JavaDoc buf, String JavaDoc id, String JavaDoc name,
85             Object JavaDoc value, Boolean JavaDoc checked)
86     throws JspException JavaDoc {
87         boolean checkedBool = (checked == null) ? false : checked.booleanValue();
88         String JavaDoc valueStr = ObjectTools.toString(getValue());
89         HtmlViewToolkit.createRadioTag(buf, id, name, valueStr, checkedBool,
90             attributes, singleAttrs);
91     }
92 }
93
Popular Tags