Author: pbenedict
Date: Mon Sep 4 17:00:46 2006
New Revision: 440206
URL: http://svn.apache.org/viewvc?view=rev&rev=440206
Log:
STR-746: New html:param tag; nestable in frame,link,rewrite tags.
Added:
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/ParamTag.java
Modified:
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/FrameTag.java
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/LinkTag.java
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/LocalStrings.properties
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/RewriteTag.java
struts/struts1/trunk/taglib/src/main/resources/META-INF/tld/struts-html.tld
Modified:
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/FrameTag.java
URL:
http://svn.apache.org/viewvc/struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/FrameTag.java?view=diff&rev=440206&r1=440205&r2=440206
==============================================================================
---
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/FrameTag.java
(original)
+++
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/FrameTag.java
Mon Sep 4 17:00:46 2006
@@ -1,7 +1,7 @@
/*
* $Id$
*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -138,11 +138,20 @@
// --------------------------------------------------------- Public Methods
/**
- * Render the appropriately encoded URI.
+ * Evaluate the body for any parameters.
*
* @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
+ return (EVAL_BODY_TAG);
+ }
+
+ /**
+ * Render the appropriately encoded URI.
+ *
+ * @throws JspException if a JSP exception has occurred
+ */
+ public int doEndTag() throws JspException {
// Print this element to our output writer
StringBuffer results = new StringBuffer("<frame");
@@ -163,15 +172,6 @@
results.append(getElementClose());
TagUtils.getInstance().write(pageContext, results.toString());
- return (SKIP_BODY);
- }
-
- /**
- * Ignore the end of this tag.
- *
- * @throws JspException if a JSP exception has occurred
- */
- public int doEndTag() throws JspException {
return (EVAL_PAGE);
}
Modified:
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/LinkTag.java
URL:
http://svn.apache.org/viewvc/struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/LinkTag.java?view=diff&rev=440206&r1=440205&r2=440206
==============================================================================
---
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/LinkTag.java
(original)
+++
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/LinkTag.java
Mon Sep 4 17:00:46 2006
@@ -1,7 +1,7 @@
/*
* $Id$
*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -136,6 +136,11 @@
* Include transaction token (if any) in the hyperlink?
*/
protected boolean transaction = false;
+
+ /**
+ * Additional parameters included programatically.
+ */
+ protected Map parameters = null;
/**
* Name of parameter to generate to hold index number
@@ -302,29 +307,6 @@
* @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
- // Generate the opening anchor element
- StringBuffer results = new StringBuffer("<a");
-
- // Special case for name anchors
- prepareAttribute(results, "name", getLinkName());
-
- // * @since Struts 1.1
- if ((getLinkName() == null) || (getForward() != null)
- || (getHref() != null) || (getPage() != null)
- || (getAction() != null)) {
- prepareAttribute(results, "href", calculateURL());
- }
-
- prepareAttribute(results, "target", getTarget());
- prepareAttribute(results, "accesskey", getAccesskey());
- prepareAttribute(results, "tabindex", getTabindex());
- results.append(prepareStyles());
- results.append(prepareEventHandlers());
- prepareOtherAttributes(results);
- results.append(">");
-
- TagUtils.getInstance().write(pageContext, results.toString());
-
// Evaluate the body of this tag
this.text = null;
@@ -354,15 +336,34 @@
* @throws JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException {
- // Prepare the textual content and ending element of this hyperlink
- StringBuffer results = new StringBuffer();
+ // Generate the opening anchor element
+ StringBuffer results = new StringBuffer("<a");
+ // Special case for name anchors
+ prepareAttribute(results, "name", getLinkName());
+
+ // * @since Struts 1.1
+ if ((getLinkName() == null) || (getForward() != null)
+ || (getHref() != null) || (getPage() != null)
+ || (getAction() != null)) {
+ prepareAttribute(results, "href", calculateURL());
+ }
+
+ prepareAttribute(results, "target", getTarget());
+ prepareAttribute(results, "accesskey", getAccesskey());
+ prepareAttribute(results, "tabindex", getTabindex());
+ results.append(prepareStyles());
+ results.append(prepareEventHandlers());
+ prepareOtherAttributes(results);
+ results.append(">");
+
+ TagUtils.getInstance().write(pageContext, results.toString());
+
+ // Prepare the textual content and ending element of this hyperlink
if (text != null) {
results.append(text);
}
-
results.append("</a>");
-
TagUtils.getInstance().write(pageContext, results.toString());
return (EVAL_PAGE);
@@ -385,6 +386,7 @@
paramName = null;
paramProperty = null;
paramScope = null;
+ parameters = null;
property = null;
scope = null;
target = null;
@@ -409,6 +411,14 @@
TagUtils.getInstance().computeParameters(pageContext, paramId,
paramName, paramProperty, paramScope, name, property, scope,
transaction);
+
+ // Add parameters collected from the tag's inner body
+ if (this.parameters != null) {
+ if (params == null) {
+ params = new HashMap();
+ }
+ params.putAll(this.parameters);
+ }
// if "indexed=true", add "index=x" parameter to query string
// * @since Struts 1.1
@@ -440,5 +450,19 @@
}
return (url);
+ }
+
+ /**
+ * <p>Adds a parameter to this link.</p>
+ *
+ * @param paramName the parameter name
+ * @param paramValue the parameter value
+ * @since Struts 1.3.6
+ */
+ public void addParameter(String paramName, Object paramValue) {
+ if (this.parameters == null) {
+ this.parameters = new HashMap();
+ }
+ this.parameters.put(paramName, paramValue);
}
}
Modified:
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/LocalStrings.properties?view=diff&rev=440206&r1=440205&r2=440206
==============================================================================
---
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/LocalStrings.properties
(original)
+++
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/LocalStrings.properties
Mon Sep 4 17:00:46 2006
@@ -27,6 +27,7 @@
includeTag.lookup=Cannot find global forward named {0}
indexed.noEnclosingIterate=indexed=\"true\" is only valid within an enclosing
iterate tag
iterateTag.iterator=Cannot create iterator for {0}
+linkParamTag.linkParam=LinkParam tag must be nested in a Link, Rewrite, or
Frame tag
linkTag.destination=You must specify exactly one of 'forward', 'href', or
'page'
linkTag.forward=Cannot locate global forwarding for {0}
linkTag.forwards=Cannot locate forwards mapping table
Added:
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/ParamTag.java
URL:
http://svn.apache.org/viewvc/struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/ParamTag.java?view=auto&rev=440206
==============================================================================
---
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/ParamTag.java
(added)
+++
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/ParamTag.java
Mon Sep 4 17:00:46 2006
@@ -0,0 +1,121 @@
+/*
+ * $Id: ParamTag.java 376841 2006-02-10 21:01:28Z pbenedict $
+ *
+ * Copyright 2006-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+package org.apache.struts.taglib.html;
+
+import org.apache.struts.util.MessageResources;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+import javax.servlet.jsp.tagext.Tag;
+
+/**
+ * Adds a new request parameter to its parent [EMAIL PROTECTED] LinkTag}.
+ *
+ * @version $Rev: 376841 $ $Date: 2005-04-06 02:37:00 -0400 (Wed, 06 Apr 2005)
+ * $
+ * @since Struts 1.3.6
+ */
+public class ParamTag extends BodyTagSupport {
+
+ /**
+ * The message resources for this package.
+ */
+ protected static MessageResources messages =
+ MessageResources.getMessageResources(Constants.Package
+ + ".LocalStrings");
+
+ /**
+ * The name of the query parameter.
+ */
+ protected String name = null;
+
+ /**
+ * The value of the query parameter or body content of this tag (if any).
+ */
+ protected String value = null;
+
+ // ----------------------------------------------------- Constructor
+
+ public ParamTag() {
+ super();
+ }
+
+ public String getName() {
+ return (this.name);
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getValue() {
+ return (this.value);
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ // --------------------------------------------------------- Public Methods
+
+ /**
+ * @throws JspException if a JSP exception has occurred
+ */
+ public int doStartTag() throws JspException {
+ return (EVAL_BODY_TAG);
+ }
+
+ /**
+ * Save the associated from the body content.
+ *
+ * @throws JspException if a JSP exception has occurred
+ */
+ public int doAfterBody() throws JspException {
+ if (this.bodyContent != null) {
+ String value = this.bodyContent.getString().trim();
+ if (value.length() > 0) {
+ this.value = value;
+ }
+ }
+ return (SKIP_BODY);
+ }
+
+ /**
+ * Render the end of the hyperlink.
+ *
+ * @throws JspException if a JSP exception has occurred
+ */
+ public int doEndTag() throws JspException {
+ Tag tag = findAncestorWithClass(this, LinkTag.class);
+ if (tag != null) {
+ ((LinkTag)tag).addParameter(this.name, this.value);
+ } else {
+ throw new
JspException(messages.getMessage("linkParamTag.linkParam"));
+ }
+ return (EVAL_PAGE);
+ }
+
+ /**
+ * Release any acquired resources.
+ */
+ public void release() {
+ super.release();
+ this.name = null;
+ this.value = null;
+ }
+}
Modified:
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/RewriteTag.java
URL:
http://svn.apache.org/viewvc/struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/RewriteTag.java?view=diff&rev=440206&r1=440205&r2=440206
==============================================================================
---
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/RewriteTag.java
(original)
+++
struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/html/RewriteTag.java
Mon Sep 4 17:00:46 2006
@@ -23,6 +23,7 @@
import java.net.MalformedURLException;
+import java.util.HashMap;
import java.util.Map;
/**
@@ -35,17 +36,25 @@
// --------------------------------------------------------- Public Methods
/**
- * Render the appropriately encoded URI.
+ * Render the URI.
*
* @throws JspException if a JSP exception has occurred
*/
- public int doStartTag() throws JspException {
+ public int doEndTag() throws JspException {
// Generate the hyperlink URL
Map params =
TagUtils.getInstance().computeParameters(pageContext, paramId,
paramName, paramProperty, paramScope, name, property, scope,
transaction);
+ // Add parameters collected from the tag's inner body
+ if (this.parameters != null) {
+ if (params == null) {
+ params = new HashMap();
+ }
+ params.putAll(this.parameters);
+ }
+
String url = null;
try {
@@ -61,16 +70,6 @@
}
TagUtils.getInstance().write(pageContext, url);
-
- return (SKIP_BODY);
- }
-
- /**
- * Ignore the end of this tag.
- *
- * @throws JspException if a JSP exception has occurred
- */
- public int doEndTag() throws JspException {
return (EVAL_PAGE);
}
}
Modified:
struts/struts1/trunk/taglib/src/main/resources/META-INF/tld/struts-html.tld
URL:
http://svn.apache.org/viewvc/struts/struts1/trunk/taglib/src/main/resources/META-INF/tld/struts-html.tld?view=diff&rev=440206&r1=440205&r2=440206
==============================================================================
--- struts/struts1/trunk/taglib/src/main/resources/META-INF/tld/struts-html.tld
(original)
+++ struts/struts1/trunk/taglib/src/main/resources/META-INF/tld/struts-html.tld
Mon Sep 4 17:00:46 2006
@@ -1990,6 +1990,7 @@
<tag>
<name>frame</name>
<tag-class>org.apache.struts.taglib.html.FrameTag</tag-class>
+ <body-content>JSP</body-content>
<description>
<![CDATA[
<p><strong>Render an HTML frame element</strong></p>
@@ -4054,6 +4055,7 @@
<tag>
<name>link</name>
<tag-class>org.apache.struts.taglib.html.LinkTag</tag-class>
+ <body-content>JSP</body-content>
<description>
<![CDATA[
<p><strong>Render an HTML anchor or hyperlink</strong></p>
@@ -4090,13 +4092,14 @@
<p>Normally, the hyperlink you specify with one of the
attributes described in the previous paragraph will be left
unchanged (other than URL rewriting if necessary). However,
- there are two ways you can append one or more dynamically
+ there are three ways you can append one or more dynamically
defined query parameters to the hyperlink -- specify a single
parameter with the <code>paramId</code> attribute (and its
associated attributes to select the value), or specify the
<code>name</code> (and optional <code>property</code>)
attributes to select a <code>java.util.Map</code> bean that
- contains one or more parameter ids and corresponding values.
+ contains one or more parameter ids and corresponding values,
+ or nest one or more lt&;html:param> tags in the tag body.
</p>
<p>To specify a single parameter, use the <code>paramId</code>
@@ -4139,6 +4142,14 @@
or an object whose toString() method will be called.
If a String array is specified, more than one value for the
same query parameter name will be created.</p>
+
+ <p>Supplmenting these two methods, you can nest one or more
+ lt&;html:param> tags to dynamically add parameters in a
+ logic-friendly way (such as executing a for loop that
+ assigns the name/value pairs at runtime). This method does
+ not compete with the aforementioned; it will adds its
+ parameters <em>in addition</em> to whatever parameters are
+ already specified.</p>
<p>Additionally, you can request that the current transaction
control token, if any, be included in the generated hyperlink
@@ -4653,6 +4664,47 @@
</attribute>
</tag>
<tag>
+ <name>param</name>
+ <tag-class>org.apache.struts.taglib.html.ParamTag</tag-class>
+ <description>
+ <![CDATA[
+ <p>Adds a parameter to the following tags:
+ <ol>
+ <li><a href="#frame"><html:frame></li>
+ <li><a href="#link"><html:link></li>
+ <li><a href="#rewrite"><html:rewrite></li>
+ </ol>
+ </p>
+
+ <dl><dt><b>Since:</b></dt>
+ <dd>Struts 1.3.6</dd></dl>
+ ]]>
+ </description>
+ <attribute>
+ <name>name</name>
+ <required>true</required>
+ <rtexprvalue>true</rtexprvalue>
+ <description>
+ <![CDATA[
+ <p>The String containing the name of the request
parameter.</p>
+ ]]>
+ </description>
+ </attribute>
+ <attribute>
+ <name>value</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ <description>
+ <![CDATA[
+ <p>The value of the request parameter specified by the
+ <code>name</code> attribute, whose return value must
+ be a String or String[] that will be dynamically added to
+ this hyperlink.</p>
+ ]]>
+ </description>
+ </attribute>
+ </tag>
+ <tag>
<name>messages</name>
<tag-class>org.apache.struts.taglib.html.MessagesTag</tag-class>
<tei-class>org.apache.struts.taglib.html.MessagesTei</tei-class>
@@ -6833,7 +6885,7 @@
<tag>
<name>rewrite</name>
<tag-class>org.apache.struts.taglib.html.RewriteTag</tag-class>
- <body-content>empty</body-content>
+ <body-content>JSP</body-content>
<description>
<![CDATA[
<p><strong>Render an URI</strong></p>