KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > model > 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.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 import com.inversoft.verge.mvc.view.jsp.JspTools;
15
16
17 /**
18  * This class is the radio box input tag.
19  *
20  * @author Brian Pontarelli
21  */

22 public class RadioTag extends com.inversoft.verge.mvc.view.jsp.html.RadioTag {
23
24     protected ModelResolution modelResolution;
25
26
27     /**
28      * Initializes the tag by checking that the tag is inside a form tag
29      *
30      * @throws JspException If this tag is not inside a form tag
31      */

32     public void initialize() throws JspException JavaDoc {
33
34         // Initialize the parent reference and the bean reference
35
super.initialize();
36         super.initializeKeyProperty();
37
38         // Check if there is another radio tag for the same model definition
39
// and if so use that tags name
40
String JavaDoc tempName = null;
41         if (!hasName()) {
42             tempName = JspTools.getRadioName(localModel, pageContext);
43             if (tempName != null) {
44                 localName = tempName;
45             } else {
46                 // If the initializers setup a new name because it was null
47
// before, add it to the PageContext
48
JspTools.setRadioName(localModel, localName, pageContext);
49             }
50         }
51
52         modelResolution = ModelHelper.getModelResolution(key, property, pageContext);
53         if (modelResolution == null) {
54             throw new JspException JavaDoc("Invalid model definition: " + getModel());
55         }
56     }
57
58     /**
59      * Outputs the extra model information
60      *
61      * @return Always returns EVAL_PAGE
62      */

63     public int doEndTag() throws JspException JavaDoc {
64         super.doEndTag();
65
66         if (isSetValue()) {
67             ModelHelper.outputModelExtra(modelResolution.getMetaData(), localName,
68                 pageContext);
69         }
70
71         return EVAL_PAGE;
72     }
73
74     /**
75      * Overrides the {@link com.inversoft.verge.mvc.view.jsp.html.RadioTag
76      * #createRadioTag(StringBuffer, String, String, Object, Boolean)
77      * super.createRadioTag()} method and determines if this radio tag instance
78      * if checked or not.
79      *
80      * @param buf The StringBuffer to append the HTML to
81      * @param checked The checked flag from the parent class
82      * @param value The value of the radio instance
83      * @throws JspException If there was any problems generating the HTML
84      */

85     protected void createRadioTag(StringBuffer JavaDoc buf, String JavaDoc id, String JavaDoc name,
86         Object JavaDoc value, Boolean JavaDoc checked)
87     throws JspException JavaDoc {
88         if (isGetValue()) {
89             Object JavaDoc valueObj = ModelHelper.getValue(modelResolution, pageContext);
90             checked = ObjectTools.areObjectsEqual(valueObj, value) ?
91                 Boolean.TRUE : Boolean.FALSE;
92         }
93
94         super.createRadioTag(buf, id, name, value, checked);
95     }
96 }
Popular Tags