KickJava   Java API By Example, From Geeks To Geeks.

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


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.verge.mvc.view.HtmlConstants;
17 import com.inversoft.verge.mvc.view.HtmlViewToolkit;
18
19
20 /**
21  * This class is the select input tag which will generate
22  * the HTML select tags.
23  *
24  * @author Brian Pontarelli
25  */

26 public class SelectTag extends InputTag {
27
28     /* The logger */
29     private static final Logger logger = Logger.getLogger(SelectTag.class);
30
31     private Boolean JavaDoc multiple;
32
33
34     /**
35      * Empty constructor
36      */

37     public SelectTag() {
38         // empty
39
}
40
41
42     /**
43      * Retrieves the tag's multiple attribute
44      *
45      * @return Returns the tag's multiple attribute
46      */

47     public Boolean JavaDoc getMultiple() {
48         return multiple;
49     }
50
51     /**
52      * Populates the tag's multiple attribute
53      *
54      * @param multiple The value of the tag's multiple attribute
55      */

56     public void setMultiple(Boolean JavaDoc multiple) {
57         this.multiple = multiple;
58     }
59
60     /**
61      * Sets up the multiple attribute of the tag, if the property was set. This
62      * also calls super.initialize().
63      *
64      * @throws JspException If there was a problem expanding variables in the
65      * super implementations
66      */

67     protected void initialize() throws JspException JavaDoc {
68         super.initialize();
69
70         if (multiple != null && multiple.booleanValue()) {
71             singleAttrs.add(HtmlConstants.MULTIPLE);
72         }
73     }
74
75     /**
76      * Generates the select HTML and returns EVAL_BODY_TAG so that the option
77      * tags get generated
78      *
79      * @return Always EVAL_BODY_INCLUDE
80      */

81     public int doStartTag() throws JspException JavaDoc {
82
83         logger.debug("Starting the select tag");
84
85         // Initialize the parent reference and the bean reference
86
initialize();
87
88         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
89         createSelectTag(buf, getId(), localName);
90
91         try {
92             pageContext.getOut().print(buf.toString());
93         } catch (IOException JavaDoc ioe) {
94             throw new JspException JavaDoc(ioe.toString());
95         }
96
97         return EVAL_BODY_INCLUDE;
98     }
99
100     /**
101      * Does the work of rendering the HTML for the select tag. This HTML is appended
102      * to the given StringBuffer.
103      *
104      * @param buf The StringBuffer to append to
105      * @throws JspException For overridding classes
106      */

107     protected void createSelectTag(StringBuffer JavaDoc buf, String JavaDoc id, String JavaDoc name)
108     throws JspException JavaDoc {
109         HtmlViewToolkit.createSelectStartTag(buf, id, name, attributes,
110             singleAttrs);
111
112         if (logger.isDebugEnabled()) {
113             logger.debug("The select tag: " + buf.toString());
114         }
115     }
116
117     /**
118      * Appends the select end tag
119      *
120      * @return Always returns EVAL_PAGE
121      */

122     public int doEndTag() throws JspException JavaDoc {
123
124         logger.debug("Outputting the select end tag");
125
126         try {
127             pageContext.getOut().print(HtmlConstants.SELECT_END_TAG);
128         } catch (IOException JavaDoc ioe) {
129             throw new JspException JavaDoc(ioe.toString());
130         }
131
132         return EVAL_PAGE;
133     }
134 }
135
Popular Tags