KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.apache.beehive.netui.tags.AbstractSimpleTag;
21 import org.apache.beehive.netui.tags.IAttributeConsumer;
22 import org.apache.beehive.netui.util.Bundle;
23
24 import javax.servlet.jsp.JspException JavaDoc;
25 import javax.servlet.jsp.tagext.JspTag JavaDoc;
26 import javax.servlet.jsp.tagext.SimpleTagSupport JavaDoc;
27
28 /**
29  * @jsptagref.tagdescription <p>Adds an attribute to the parent tag rendered in the browser.</p>
30  *
31  * <p>The following &lt;netui:attribute> tags are rendered within the &lt;span> tag in the browser.
32  *
33  * <pre> &lt;netui:span value="Some Text">
34  * &lt;netui:attribute name="a" value="aVal" />
35  * &lt;netui:attribute name="b" value="bVal" />
36  * &lt;netui:attribute name="c" value="cVal" />
37  * &lt;/netui:span></pre>
38  *
39  * <p>The HTML rendered in the browser appears as follows.
40  *
41  * <pre> &lt;span a="aVal" b="bVal" c="cVal">Some Text&lt;/span></pre>
42  *
43  * Note that the <code>value</code> attribute can be dynamically determined using a databinding expression.
44  *
45  * <pre> &lt;netui:attribute name="a" value="${pageFlow.aAttributeValue}" /></pre>
46  * @netui:tag name="attribute" body-content="empty" description="Add an attribute to the parent tag which be rendered."
47  */

48 public class Attribute extends AbstractSimpleTag
49 {
50     private String JavaDoc _name = null;
51     private String JavaDoc _value = null;
52     private String JavaDoc _facet = null;
53
54     /**
55      * Return the name of the Tag.
56      */

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

71     public void setName(String JavaDoc name)
72             throws JspException JavaDoc
73     {
74         _name = setRequiredValueAttribute(name, "name");
75     }
76
77     /**
78      * Sets the <code>value</code> attribute.
79      * @param value the value of the attribute.
80      * @jsptagref.attributedescription The value of the attribute to add to the parent tag.
81      * @jsptagref.databindable true
82      * @jsptagref.attributesyntaxvalue <i>string_or_expression_value</i>
83      * @netui:attribute required="true" rtexprvalue="true"
84      * description="The value of the attribute to add to the parent tag."
85      */

86     public void setValue(String JavaDoc value)
87     {
88         _value = setNonEmptyValueAttribute(value);
89     }
90
91     /**
92      * Sets the <code>facet</code> attribute.
93      * @param facet the value of the <code>facet</code> attribute.
94      * @jsptagref.attributedescription The name of the facet targetted by the attribute.
95      * @jsptagref.databindable false
96      * @jsptagref.attributesyntaxvalue <i>string_or_expression_value</i>
97      * @netui:attribute rtexprvalue="true"
98      * description="The name of the facet targetted by the attribute."
99      */

100     public void setFacet(String JavaDoc facet)
101             throws JspException JavaDoc
102     {
103         _facet = setRequiredValueAttribute(facet, "facet");
104     }
105
106     /**
107      * Add the URL parameter to the Parameter's parent.
108      * @throws JspException if a JSP exception has occurred
109      */

110     public void doTag()
111             throws JspException JavaDoc
112     {
113         if (hasErrors()) {
114             reportErrors();
115             return;
116         }
117
118         JspTag JavaDoc tag = SimpleTagSupport.findAncestorWithClass(this, IAttributeConsumer.class);
119         if (!(tag instanceof IAttributeConsumer)) {
120             String JavaDoc s = Bundle.getString("Tags_AttributeInvalidParent");
121             registerTagError(s, null);
122             reportErrors();
123             return;
124         }
125
126         IAttributeConsumer ac = (IAttributeConsumer) tag;
127         ac.setAttribute(_name, _value, _facet);
128         return;
129     }
130 }
131
Popular Tags