KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > model > ParamTag


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.verge.mvc.model.ModelResolution;
13 import com.inversoft.verge.mvc.view.jsp.html.ATag;
14 import com.inversoft.verge.mvc.view.jsp.html.BaseModelTag;
15
16
17 /**
18  * This class is used to set model values within an anchor
19  * tag. This tells the server that when the anchor tag is
20  * clicked, the model object should have one of its
21  * properties set to a specific value.
22  *
23  * @author Brian Pontarelli
24  */

25 public class ParamTag extends BaseModelTag {
26
27     protected ModelResolution modelResolution;
28
29
30     /**
31      * Initializes the tag by checking that the tag is inside a form tag
32      *
33      * @throws javax.servlet.jsp.JspException If this tag is not inside a form tag
34      */

35     public void initialize() throws JspException JavaDoc {
36
37         // Initialize the parent reference
38
super.initialize();
39         super.initializeKeyProperty();
40
41         modelResolution = ModelHelper.getModelResolution(key, property, pageContext);
42         if (modelResolution == null) {
43             throw new JspException JavaDoc("Invalid model definition: " + getModel());
44         }
45     }
46
47     /**
48      * Calls initialize
49      */

50     public int doStartTag() throws JspException JavaDoc{
51         initialize();
52
53         return SKIP_BODY;
54     }
55
56     /**
57      * Generates a usable URL parameter that will set a model objects value and
58      * adds it to the list of parameters in the anchor tag parent.
59      */

60     public int doEndTag() throws JspException JavaDoc {
61         super.doEndTag();
62
63         ATag parent = (ATag) findAncestorWithClass(this, ATag.class);
64         if (parent == null) {
65             throw new JspException JavaDoc("[ParamTag] - param tags must be used within" +
66                 " anchor tags");
67         }
68
69         ModelHelper.generateModelExtraParams(parent.getParameterMap(),
70             modelResolution.getMetaData(), localName, localValue);
71
72         return EVAL_PAGE;
73     }
74 }
Popular Tags