KickJava   Java API By Example, From Geeks To Geeks.

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


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.IBehaviorConsumer;
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 Add an attribute to the parent tag rendered.
30  * @netui:tag name="behavior" body-content="empty" description="Add an attribute to the parent tag rendered."
31  */

32 public class Behavior extends AbstractSimpleTag
33 {
34     private String JavaDoc _name = null;
35     private Object JavaDoc _value = null;
36     private String JavaDoc _facet = null;
37
38     /**
39      * Return the name of the Tag.
40      */

41     public String JavaDoc getTagName() {
42         return "Behavior";
43     }
44
45     /**
46      * Sets the <code>name</code> behavior.
47      * @param name the value of the <code>name</code> behavior.
48      * @jsptagref.attributedescription The name of the behavior to add to the parent tag.
49      * @jsptagref.databindable false
50      * @jsptagref.attributesyntaxvalue <i>string_name</i>
51      * @netui:attribute required="true" rtexprvalue="true"
52      * description="The name of the behavior to add to the parent tag."
53      */

54     public void setName(String JavaDoc name)
55             throws JspException JavaDoc
56     {
57         _name = setRequiredValueAttribute(name, "name");
58     }
59
60     /**
61      * Sets the <code>value</code> behavior.
62      * @param value the value of the <code>name</code> behavior.
63      * @jsptagref.attributedescription The value of the behavior to add to the parent tag.
64      * @jsptagref.databindable true
65      * @jsptagref.attributesyntaxvalue <i>string_or_expression_value</i>
66      * @netui:attribute required="true" rtexprvalue="true"
67      * description="The value of the behavior to add to the parent tag."
68      */

69     public void setValue(Object JavaDoc value)
70     {
71         _value = value;
72     }
73
74     /**
75      * Sets the <code>facet</code> behavior.
76      * @param facet the value of the <code>facet</code> attribute.
77      * @jsptagref.attributedescription The name of the facet targetted by the behavior.
78      * @jsptagref.databindable true
79      * @jsptagref.attributesyntaxvalue <i>string_or_expression_value</i>
80      * @netui:attribute rtexprvalue="true"
81      * description="The name of the facet targetted by the behavior."
82      */

83     public void setFacet(String JavaDoc facet)
84             throws JspException JavaDoc
85     {
86         _facet = setRequiredValueAttribute(facet, "facet");
87     }
88
89     /**
90      * Add the name/value pair to the IBehaviorConsumer parent of the tag.
91      * @throws JspException if a JSP exception has occurred
92      */

93     public void doTag()
94             throws JspException JavaDoc
95     {
96         if (hasErrors()) {
97             reportErrors();
98             return;
99         }
100
101         JspTag JavaDoc tag = SimpleTagSupport.findAncestorWithClass(this, IBehaviorConsumer.class);
102         if (tag == null) {
103             String JavaDoc s = Bundle.getString("Tags_BehaviorInvalidParent");
104             registerTagError(s, null);
105             reportErrors();
106             return;
107         }
108
109         IBehaviorConsumer ac = (IBehaviorConsumer) tag;
110         ac.setBehavior(_name, _value, _facet);
111         return;
112     }
113 }
114
Popular Tags