001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.tags.html;
020:
021: import org.apache.beehive.netui.tags.AbstractSimpleTag;
022: import org.apache.beehive.netui.tags.IBehaviorConsumer;
023: import org.apache.beehive.netui.util.Bundle;
024:
025: import javax.servlet.jsp.JspException;
026: import javax.servlet.jsp.tagext.JspTag;
027: import javax.servlet.jsp.tagext.SimpleTagSupport;
028:
029: /**
030: * @jsptagref.tagdescription Add an attribute to the parent tag rendered.
031: * @netui:tag name="behavior" body-content="empty" description="Add an attribute to the parent tag rendered."
032: */
033: public class Behavior extends AbstractSimpleTag {
034: private String _name = null;
035: private Object _value = null;
036: private String _facet = null;
037:
038: /**
039: * Return the name of the Tag.
040: */
041: public String getTagName() {
042: return "Behavior";
043: }
044:
045: /**
046: * Sets the <code>name</code> behavior.
047: * @param name the value of the <code>name</code> behavior.
048: * @jsptagref.attributedescription The name of the behavior to add to the parent tag.
049: * @jsptagref.databindable false
050: * @jsptagref.attributesyntaxvalue <i>string_name</i>
051: * @netui:attribute required="true" rtexprvalue="true"
052: * description="The name of the behavior to add to the parent tag."
053: */
054: public void setName(String name) throws JspException {
055: _name = setRequiredValueAttribute(name, "name");
056: }
057:
058: /**
059: * Sets the <code>value</code> behavior.
060: * @param value the value of the <code>name</code> behavior.
061: * @jsptagref.attributedescription The value of the behavior to add to the parent tag.
062: * @jsptagref.databindable true
063: * @jsptagref.attributesyntaxvalue <i>string_or_expression_value</i>
064: * @netui:attribute required="true" rtexprvalue="true"
065: * description="The value of the behavior to add to the parent tag."
066: */
067: public void setValue(Object value) {
068: _value = value;
069: }
070:
071: /**
072: * Sets the <code>facet</code> behavior.
073: * @param facet the value of the <code>facet</code> attribute.
074: * @jsptagref.attributedescription The name of the facet targetted by the behavior.
075: * @jsptagref.databindable true
076: * @jsptagref.attributesyntaxvalue <i>string_or_expression_value</i>
077: * @netui:attribute rtexprvalue="true"
078: * description="The name of the facet targetted by the behavior."
079: */
080: public void setFacet(String facet) throws JspException {
081: _facet = setRequiredValueAttribute(facet, "facet");
082: }
083:
084: /**
085: * Add the name/value pair to the IBehaviorConsumer parent of the tag.
086: * @throws JspException if a JSP exception has occurred
087: */
088: public void doTag() throws JspException {
089: if (hasErrors()) {
090: reportErrors();
091: return;
092: }
093:
094: JspTag tag = SimpleTagSupport.findAncestorWithClass(this ,
095: IBehaviorConsumer.class);
096: if (tag == null) {
097: String s = Bundle.getString("Tags_BehaviorInvalidParent");
098: registerTagError(s, null);
099: reportErrors();
100: return;
101: }
102:
103: IBehaviorConsumer ac = (IBehaviorConsumer) tag;
104: ac.setBehavior(_name, _value, _facet);
105: return;
106: }
107: }
|