Index: apps/examples/src/main/webapp/exercise/html-attribute.jsp
===================================================================
--- apps/examples/src/main/webapp/exercise/html-attribute.jsp (revision 0)
+++ apps/examples/src/main/webapp/exercise/html-attribute.jsp (revision 0)
@@ -0,0 +1,181 @@
+<%--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+--%>
+<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
+<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
+<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
+
+
+ Test <html:attr> Tag
+
+
+
+ <html:attr> Tag Test
+
+
+
+ <html:button>
+
+
+
+
+ Button title from <html:attr> body
+
+
+
+
+ <html:cancel>
+
+
+
+
+ alert('Cancel onclick overriden by <html:attr>');
+
+
+
+
+ <html:checkbox>
+
+
+ Click the checkbox to see an alert
+
+
+ alert('checkbox onclick from by <html:attr>');
+
+
+
+
+ <html:file> Tag
+
+
+ <html:hidden>
+
+ View source to see generated html!
+
+
+
+
+
+ <html:image>
+
+
+
+
+ Image value that needs
+
+
+
+
+ <html:img>
+
+
+ <html:link>
+
+
+ Click the link to see an alert from <html:attr> body
+
+
+ alert('link onclick from by attr tag');
+
+
+
+
+ <html:multibox>
+
+
+ CONSTANT_VALUE
+
+
+ alert('multibox onclick from by attr body');
+
+
+ Click the multibox to see an alert
+
+
+ <html:password>
+
+
+ CONSTANT_VALUE
+
+
+ 123
+
+
+
+
+ <html:radio>
+
+
+ Click the radio to see an alert from <html:attr> body
+
+
+ alert('radio onclick from by attr tag');
+
+
+
+
+ <html:select>
+
+
+
+
+ alert('select onclick from by attr tag');
+
+
+
+
+ <html:submit>
+
+
+
+
+ submit title from body
+
+
+
+
+ <html:textarea>
+
+
+
+
+ textarea value from tag
+
+
+
+
+ <html:text>
+
+
+
+
+ text value from tag
+
+
+
+
+
+
+
+
Property changes on: apps\examples\src\main\webapp\exercise\html-attribute.jsp
___________________________________________________________________
Name: svn:keywords
+ Date Author Id Revision HeadURL
Name: svn:eol-style
+ native
Index: apps/examples/src/main/webapp/exercise/index.html
===================================================================
--- apps/examples/src/main/webapp/exercise/index.html (revision 510255)
+++ apps/examples/src/main/webapp/exercise/index.html (working copy)
@@ -58,6 +58,8 @@
HTML Tags
+ <html:attr>
+
<html:cancel>
<html:img>
Index: apps/examples/src/main/webapp/WEB-INF/exercise/struts-config.xml
===================================================================
--- apps/examples/src/main/webapp/WEB-INF/exercise/struts-config.xml (revision 510255)
+++ apps/examples/src/main/webapp/WEB-INF/exercise/struts-config.xml (working copy)
@@ -43,6 +43,12 @@
+
+
+
+
0) {
+ internalValue = TagUtils.getInstance().filter(bodyValue);
+ }
+ }
+ return (SKIP_BODY);
+ }
+
+ /**
+ * Render the end of the hyperlink.
+ *
+ * @throws JspException if a JSP exception has occurred
+ */
+ public int doEndTag() throws JspException {
+ AttributeParent tag = (AttributeParent)findAncestorWithClass(this, AttributeParent.class);
+ if (tag != null) {
+ if (internalValue != null) {
+ tag.setAttribute(name, internalValue);
+ }
+ } else {
+ throw new JspException(messages.getMessage("AttributeTag.parent"));
+ }
+ return (EVAL_PAGE);
+ }
+
+ /**
+ * Release any acquired resources.
+ */
+ public void release() {
+ super.release();
+ this.name = null;
+ this.value = null;
+ internalValue = null;
+ }
+}
Property changes on: taglib\src\main\java\org\apache\struts\taglib\html\AttributeTag.java
___________________________________________________________________
Name: svn:keywords
+ Date Author Id Revision HeadURL
Name: svn:eol-style
+ native
Index: taglib/src/main/java/org/apache/struts/taglib/html/BaseFieldTag.java
===================================================================
--- taglib/src/main/java/org/apache/struts/taglib/html/BaseFieldTag.java (revision 510255)
+++ taglib/src/main/java/org/apache/struts/taglib/html/BaseFieldTag.java (working copy)
@@ -77,12 +77,25 @@
* @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
- TagUtils.getInstance().write(this.pageContext, this.renderInputElement());
+ clearAttributes();
return (EVAL_BODY_TAG);
}
/**
+ * Now do rendering in the doEndTag() method - to allow for attribute processing.
+ *
+ * @since 1.3.7
+ * @throws JspException if a JSP exception has occurred
+ */
+ public int doEndTag() throws JspException {
+
+ TagUtils.getInstance().write(this.pageContext, this.renderInputElement());
+
+ return (EVAL_PAGE);
+ }
+
+ /**
* Renders a fully formed <input> element.
*
* @throws JspException
@@ -115,18 +128,15 @@
*/
protected void prepareValue(StringBuffer results)
throws JspException {
- results.append(" value=\"");
+ Object renderValue = null;
if (value != null) {
- results.append(this.formatValue(value));
+ renderValue = formatValue(value);
} else if (redisplay || !"password".equals(type)) {
- Object value =
+ renderValue =
TagUtils.getInstance().lookup(pageContext, name, property, null);
-
- results.append(this.formatValue(value));
}
-
- results.append('"');
+ prepareAttribute(results, "value", renderValue);
}
/**
Index: taglib/src/main/java/org/apache/struts/taglib/html/BaseHandlerTag.java
===================================================================
--- taglib/src/main/java/org/apache/struts/taglib/html/BaseHandlerTag.java (revision 510255)
+++ taglib/src/main/java/org/apache/struts/taglib/html/BaseHandlerTag.java (working copy)
@@ -20,6 +20,10 @@
*/
package org.apache.struts.taglib.html;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -45,7 +49,7 @@
*
* @version $Rev$ $Date$
*/
-public abstract class BaseHandlerTag extends BodyTagSupport {
+public abstract class BaseHandlerTag extends BodyTagSupport implements AttributeParent {
/**
* Commons Logging instance.
*/
@@ -60,6 +64,11 @@
MessageResources.getMessageResources(Constants.Package
+ ".LocalStrings");
+ /**
+ * Access key character.
+ */
+ private Map attributes;
+
// Navigation Management
/**
@@ -777,10 +786,25 @@
// --------------------------------------------------------- Public Methods
/**
+ * Set an attribute.
+ *
+ * @param name The attribute name
+ * @param name The attribute value
+ * @since Struts 1.3.7
+ */
+ public void setAttribute(String name, Object value) {
+ if (attributes == null) {
+ attributes = new HashMap();
+ }
+ attributes.put(name.toLowerCase(), value);
+ }
+
+ /**
* Release any acquired resources.
*/
public void release() {
super.release();
+ clearAttributes();
accesskey = null;
alt = null;
altKey = null;
@@ -820,6 +844,39 @@
// ------------------------------------------------------ Protected Methods
/**
+ * Retrieve an attribute value.
+ *
+ * @param name The attribute name
+ * @return The attribute value
+ * @since Struts 1.3.7
+ */
+ protected Object getAttribute(String name) {
+ return (attributes == null ? null : attributes.get(name.toLowerCase()));
+ }
+
+ /**
+ * Return the set of attributes names.
+ *
+ * @return The set of attribute names
+ * @since Struts 1.3.7
+ */
+ protected Iterator getAttributeNames(String name) {
+ Map map = (attributes == null ? Collections.EMPTY_MAP : attributes);
+ return map.keySet().iterator();
+ }
+
+ /**
+ * Clear any attribute values.
+ *
+ * @since Struts 1.3.7
+ */
+ protected void clearAttributes() {
+ if (attributes != null) {
+ attributes.clear();
+ }
+ }
+
+ /**
* Return the text specified by the literal value or the message resources
* key, if any; otherwise return null.
*
@@ -1154,11 +1211,17 @@
*/
protected void prepareAttribute(StringBuffer handlers, String name,
Object value) {
- if (value != null) {
+ Object attrValue = getAttribute(name);
+ if (attrValue == null) {
+ attrValue = value;
+ } else {
+ attributes.remove(name);
+ }
+ if (attrValue != null) {
handlers.append(" ");
handlers.append(name);
handlers.append("=\"");
- handlers.append(value);
+ handlers.append(attrValue);
handlers.append("\"");
}
}
Index: taglib/src/main/java/org/apache/struts/taglib/html/BaseInputTag.java
===================================================================
--- taglib/src/main/java/org/apache/struts/taglib/html/BaseInputTag.java (revision 510255)
+++ taglib/src/main/java/org/apache/struts/taglib/html/BaseInputTag.java (working copy)
@@ -187,6 +187,7 @@
* @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
+ clearAttributes();
return (EVAL_BODY_TAG);
}
Index: taglib/src/main/java/org/apache/struts/taglib/html/CheckboxTag.java
===================================================================
--- taglib/src/main/java/org/apache/struts/taglib/html/CheckboxTag.java (revision 510255)
+++ taglib/src/main/java/org/apache/struts/taglib/html/CheckboxTag.java (working copy)
@@ -112,27 +112,8 @@
* @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
- // Create an appropriate "input" element based on our parameters
- StringBuffer results = new StringBuffer("
+ attr
+ org.apache.struts.taglib.html.AttributeTag
+
+ Adds an attribute to any tag that implements AttributeParent.
+ This tag is supported by the following Struts tags:
+
+ <html:button>
+ <html:cancel>
+ <html:checkbox>
+ <html:file>
+ <html:frame>
+ <html:hidden>
+ <html:image>
+ <html:img>
+ <html:link>
+ <html:multibox>
+ <html:password>
+ <html:radio>
+ <html:select>
+ <html:submit>
+ <html:textarea>
+ <html:text>
+
+
+
+ Since:
+ Struts 1.3.7
+ ]]>
+
+
+ name
+ true
+ true
+
+ The String containing the name of the attribute.
+ ]]>
+
+
+
+ value
+ false
+ true
+
+ The value of the attribute specified by the
+ name attribute, whose value
+ will be dynamically added to the parent tag.
+ ]]>
+
+
+
+
base
org.apache.struts.taglib.html.BaseTag
empty
@@ -2591,7 +2645,7 @@
hidden
org.apache.struts.taglib.html.HiddenTag
- empty
+ JSP
@@ -3446,7 +3500,7 @@
img
org.apache.struts.taglib.html.ImgTag
- empty
+ JSP
Render an HTML img tag