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.IAttributeConsumer;
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 <p>Adds an attribute to the parent tag rendered in the browser.</p>
031: *
032: * <p>The following <netui:attribute> tags are rendered within the <span> tag in the browser.
033: *
034: * <pre> <netui:span value="Some Text">
035: * <netui:attribute name="a" value="aVal" />
036: * <netui:attribute name="b" value="bVal" />
037: * <netui:attribute name="c" value="cVal" />
038: * </netui:span></pre>
039: *
040: * <p>The HTML rendered in the browser appears as follows.
041: *
042: * <pre> <span a="aVal" b="bVal" c="cVal">Some Text</span></pre>
043: *
044: * Note that the <code>value</code> attribute can be dynamically determined using a databinding expression.
045: *
046: * <pre> <netui:attribute name="a" value="${pageFlow.aAttributeValue}" /></pre>
047: * @netui:tag name="attribute" body-content="empty" description="Add an attribute to the parent tag which be rendered."
048: */
049: public class Attribute extends AbstractSimpleTag {
050: private String _name = null;
051: private String _value = null;
052: private String _facet = null;
053:
054: /**
055: * Return the name of the Tag.
056: */
057: public String getTagName() {
058: return "Attribute";
059: }
060:
061: /**
062: * Sets the <code>name</code> attribute.
063: * @param name the name of the attribute.
064: * @jsptagref.attributedescription The name of the attribute to add to the parent tag.
065: * @jsptagref.databindable false
066: * @jsptagref.attributesyntaxvalue <i>string_name</i>
067: * @netui:attribute required="true" rtexprvalue="true"
068: * description="The name of the attribute to add to the parent tag."
069: */
070: public void setName(String name) throws JspException {
071: _name = setRequiredValueAttribute(name, "name");
072: }
073:
074: /**
075: * Sets the <code>value</code> attribute.
076: * @param value the value of the attribute.
077: * @jsptagref.attributedescription The value of the attribute to add to the parent tag.
078: * @jsptagref.databindable true
079: * @jsptagref.attributesyntaxvalue <i>string_or_expression_value</i>
080: * @netui:attribute required="true" rtexprvalue="true"
081: * description="The value of the attribute to add to the parent tag."
082: */
083: public void setValue(String value) {
084: _value = setNonEmptyValueAttribute(value);
085: }
086:
087: /**
088: * Sets the <code>facet</code> attribute.
089: * @param facet the value of the <code>facet</code> attribute.
090: * @jsptagref.attributedescription The name of the facet targetted by the attribute.
091: * @jsptagref.databindable false
092: * @jsptagref.attributesyntaxvalue <i>string_or_expression_value</i>
093: * @netui:attribute rtexprvalue="true"
094: * description="The name of the facet targetted by the attribute."
095: */
096: public void setFacet(String facet) throws JspException {
097: _facet = setRequiredValueAttribute(facet, "facet");
098: }
099:
100: /**
101: * Add the URL parameter to the Parameter's parent.
102: * @throws JspException if a JSP exception has occurred
103: */
104: public void doTag() throws JspException {
105: if (hasErrors()) {
106: reportErrors();
107: return;
108: }
109:
110: JspTag tag = SimpleTagSupport.findAncestorWithClass(this ,
111: IAttributeConsumer.class);
112: if (!(tag instanceof IAttributeConsumer)) {
113: String s = Bundle.getString("Tags_AttributeInvalidParent");
114: registerTagError(s, null);
115: reportErrors();
116: return;
117: }
118:
119: IAttributeConsumer ac = (IAttributeConsumer) tag;
120: ac.setAttribute(_name, _value, _facet);
121: return;
122: }
123: }
|