KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > servlet > http > jsp > tagext > CheckBoxObjectTag


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.servlet.http.jsp.tagext;
8
9 import javax.servlet.jsp.JspException JavaDoc;
10 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
11
12 import org.apache.struts.util.RequestUtils;
13 import org.apache.struts.util.ResponseUtils;
14
15 /**
16  * Tag that generates an HTML checkbox input field
17  * <p>
18  * The field is created with :<ul>
19  * <li>The <code>id</code> parameter : used as the name</li>
20  * <li>The <code>name</code>,<code>property</code> and <code>scope</code> parameter : used to fetch an object. This object is then used as the value</li>
21  * <li>The <code>value</code> parameter : used to check/uncheck the field</li>
22  * </ul>
23  * </p>
24  *
25  * @author Laurent Etiemble
26  * @version $Revision: 1.5 $
27  * @jsp:tag name="checkbox"
28  * body-content="empty"
29  */

30 public class CheckBoxObjectTag extends TagSupport JavaDoc
31 {
32    /** Id property of the tag */
33    protected String JavaDoc id = null;
34    /** Name property of the tag */
35    protected String JavaDoc name = null;
36    /** Property property of the tag */
37    protected String JavaDoc property = null;
38    /** Scope property of the tag */
39    protected String JavaDoc scope = null;
40    /** Value property of the tag */
41    protected String JavaDoc value = "true";
42
43
44    /**
45     * Executed when the start tag is encountered
46     *
47     * @return An int value to resume or not the processing
48     * @exception JspException In case of problem
49     */

50    public int doStartTag()
51       throws JspException JavaDoc
52    {
53       Object JavaDoc object = null;
54
55       // Look up the requested bean (if necessary)
56
if (property != null)
57       {
58          object = RequestUtils.lookup(pageContext, this.name, this.property, this.scope);
59       }
60       else
61       {
62          object = RequestUtils.lookup(pageContext, this.name, this.scope);
63       }
64
65       if (object == null)
66       {
67          throw new JspException JavaDoc("Unable to find bean " + this.name + " or its property " + this.property);
68       }
69
70       // Output the field
71
StringBuffer JavaDoc output = new StringBuffer JavaDoc();
72       output.append("<input type=\"checkbox\" name=\"");
73       output.append(this.id);
74       output.append("\"");
75       if (Boolean.valueOf(object.toString()).booleanValue())
76       {
77          output.append(" checked");
78       }
79       output.append(" value=\"");
80       output.append(ResponseUtils.filter(this.value.toString()));
81       output.append("\"/>");
82
83       ResponseUtils.write(pageContext, output.toString());
84
85       // Continue processing this page
86
return (SKIP_BODY);
87    }
88
89
90    /**
91     * Gets the id value of this tag
92     *
93     * @return The id value
94     * @jsp:attribute name="id"
95     * required="true"
96     * rtexprvalue="true"
97     */

98    public String JavaDoc getId()
99    {
100       return this.id;
101    }
102
103
104    /**
105     * Gets the name value of this tag
106     *
107     * @return The name value
108     * @jsp:attribute name="name"
109     * required="true"
110     * rtexprvalue="true"
111     */

112    public String JavaDoc getName()
113    {
114       return this.name;
115    }
116
117
118    /**
119     * Gets the property value of this tag
120     *
121     * @return The property value
122     * @jsp:attribute name="property"
123     * required="false"
124     * rtexprvalue="true"
125     */

126    public String JavaDoc getProperty()
127    {
128       return this.property;
129    }
130
131
132    /**
133     * Gets the scope value of this tag
134     *
135     * @return The scope value
136     * @jsp:attribute name="scope"
137     * required="false"
138     * rtexprvalue="true"
139     */

140    public String JavaDoc getScope()
141    {
142       return this.scope;
143    }
144
145
146    /**
147     * Gets the value value of this tag
148     *
149     * @return The value value
150     * @jsp:attribute name="value"
151     * required="false"
152     * rtexprvalue="true"
153     */

154    public String JavaDoc getValue()
155    {
156       return this.value;
157    }
158
159
160    /** Release all allocated resources. */
161    public void release()
162    {
163       super.release();
164       this.id = null;
165       this.name = null;
166       this.property = null;
167       this.scope = null;
168       this.value = "true";
169    }
170
171
172    /**
173     * Sets the id value of this tag
174     *
175     * @param id The new id value
176     */

177    public void setId(String JavaDoc id)
178    {
179       this.id = id;
180    }
181
182
183    /**
184     * Sets the name value of this tag
185     *
186     * @param name The new name value
187     */

188    public void setName(String JavaDoc name)
189    {
190       this.name = name;
191    }
192
193
194    /**
195     * Sets the property value of this tag
196     *
197     * @param property The new property value
198     */

199    public void setProperty(String JavaDoc property)
200    {
201       this.property = property;
202    }
203
204
205    /**
206     * Sets the scope value of this tag
207     *
208     * @param scope The new scope value
209     */

210    public void setScope(String JavaDoc scope)
211    {
212       this.scope = scope;
213    }
214
215
216    /**
217     * Sets the value value of this tag
218     *
219     * @param value The new value value
220     */

221    public void setValue(String JavaDoc value)
222    {
223       this.value = value;
224    }
225 }
226
227
Popular Tags