KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > model > 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.model;
8
9
10 import javax.servlet.jsp.JspException JavaDoc;
11
12 import com.inversoft.util.ObjectTools;
13 import com.inversoft.verge.mvc.model.ModelResolution;
14
15
16 /**
17  * This class is the check box input tag.
18  *
19  * @author Brian Pontarelli
20  */

21 public class CheckboxTag extends com.inversoft.verge.mvc.view.jsp.html.CheckboxTag {
22
23     protected ModelResolution modelResolution;
24
25
26     /**
27      * After the super class finds its form tag parent, this ensures that that
28      * form tag is from this package.
29      */

30     public void initialize() throws JspException JavaDoc {
31         super.initialize();
32         super.initializeKeyProperty();
33
34         modelResolution = ModelHelper.getModelResolution(key, property, pageContext);
35         if (modelResolution == null) {
36             throw new JspException JavaDoc("Invalid model definition: " + getModel());
37         }
38     }
39
40     /**
41      * Overrides the {@link com.inversoft.verge.mvc.view.jsp.html.CheckboxTag
42      * #createCheckboxTag(StringBuffer, String, String, Object, Boolean)
43      * super.createCheckboxTag()} method and calculates whether or not this
44      * particular checkbox instance is checked or not.
45      *
46      * @param buf The StringBuffer to append the HTML to
47      * @param checked The checked flag from the doStartTag method of the parent
48      * class
49      * @throws JspException If there was any problems generating the HTML
50      */

51     protected void createCheckboxTag(StringBuffer JavaDoc buf, String JavaDoc id, String JavaDoc name,
52             Object JavaDoc value, Boolean JavaDoc checked)
53     throws JspException JavaDoc {
54         if (isGetValue()) {
55             Object JavaDoc modelValue = ModelHelper.getValue(modelResolution, pageContext);
56             checked = ObjectTools.areObjectsEqual(modelValue, value) ?
57                 Boolean.TRUE : Boolean.FALSE;
58         }
59
60         super.createCheckboxTag(buf, id, name, value, checked);
61     }
62
63     /**
64      * Outputs the extra information required by the container to decode the
65      * model and handle the MVC
66      */

67     public int doEndTag() throws JspException JavaDoc {
68         super.doEndTag();
69         if (isSetValue()) {
70             ModelHelper.outputModelExtra(modelResolution.getMetaData(), localName,
71                 pageContext);
72         }
73
74         return EVAL_PAGE;
75     }
76 }
Popular Tags