KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > tags > html > Parameter


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.tags.html;
19
20 // java imports
21

22 // internal imports
23

24 import org.apache.beehive.netui.tags.AbstractClassicTag;
25 import org.apache.beehive.netui.util.Bundle;
26
27 import javax.servlet.jsp.JspException JavaDoc;
28 import javax.servlet.jsp.tagext.JspTag JavaDoc;
29 import javax.servlet.jsp.tagext.SimpleTagSupport JavaDoc;
30
31 /**
32  * Writes a URL parameter to a URL on its parent tag. The parent tag must implement IUrlParams.
33  * @jsptagref.tagdescription Writes a name/value pair to the URL or the parent tag.
34  *
35  * You can dynamically determine the value of the <netui:parameter> through
36  * the <code>value</code> attribute.
37  * @example In this sample, the hyperlink is amended with the parameter <code>q=Socrates</code>
38  *
39  * <pre> &lt;netui:anchor HREF="http://www.google.com/search">
40  * Search Google with the query "Socrates"
41  * &lt;netui:parameter name="q" value="Socrates" />
42  * &lt;/netui:anchor></pre>
43  *
44  * The URL produced appears below:
45  *
46  * <pre> http://www.google.com/search?q=Socrates</pre>
47  * @netui:tag name="parameter" description="Writes a URL parameter to a URL on its parent tag."
48  */

49 public class Parameter
50         extends AbstractClassicTag
51 {
52     private String JavaDoc _name = null;
53     private Object JavaDoc _value = null;
54
55     /**
56      * Return the name of the Tag.
57      */

58     public String JavaDoc getTagName()
59     {
60         return "Parameter";
61     }
62
63     /**
64      * Sets the name of the URL parameter.
65      * @param name the parameter name.
66      * @jsptagref.attributedescription The name of the parameter.
67      * @jsptagref.databindable false
68      * @jsptagref.attributesyntaxvalue <i>string_name</i>
69      * @netui:attribute required="true" rtexprvalue="true"
70      * description="The name of the parameter."
71      */

72     public void setName(String JavaDoc name)
73     {
74         _name = name;
75     }
76
77     /**
78      * Sets the value of the URL parameter. This can be an expression.
79      * @param value the parameter value.
80      * @jsptagref.attributedescription The value of the parameter. May be a literal or a data binding expression.
81      * @jsptagref.databindable true
82      * @jsptagref.attributesyntaxvalue <i>string_or_expression_value</i>
83      * @netui:attribute required="true" rtexprvalue="true" type="java.lang.Object"
84      * description="The value of the parameter."
85      */

86     public void setValue(Object JavaDoc value)
87             throws JspException JavaDoc
88     {
89         _value = value;
90     }
91
92     /**
93      * Add the URL parameter to the Parameter's parent.
94      * @throws JspException if a JSP exception has occurred
95      */

96     public int doStartTag() throws JspException JavaDoc
97     {
98         JspTag JavaDoc parentTag = SimpleTagSupport.findAncestorWithClass(this, IUrlParams.class);
99         if (parentTag == null) {
100             String JavaDoc msg = Bundle.getString("Tags_InvalidParameterParent");
101             registerTagError(msg, null);
102             reportErrors();
103         }
104         else {
105             IUrlParams parent = (IUrlParams) parentTag;
106             parent.addParameter(_name, _value, null);
107         }
108         localRelease();
109         return SKIP_BODY;
110     }
111
112     /**
113      * Release any acquired resources.
114      */

115     protected void localRelease()
116     {
117         super.localRelease();
118
119         _name = null;
120         _value = null;
121     }
122 }
123
Popular Tags