craigmcc 01/03/10 15:55:39
Modified: src/doc release-notes-1.0-b2.xml struts-html.xml
src/share/org/apache/struts/taglib/html LinkTag.java
Log:
Add an optional transaction="true" attribute to the <html:link> that will
cause the generated hyperlink to include any transaction control token
that currently exists. That way, a user who clicks this hyperlink will be
considered to be participating in the current transaction -- in
particular, calling isTokenValid() in the corresponding action will return
true.
Submitted by: Mike McCallister
PR: Bugzilla #874
Revision Changes Path
1.5 +4 -0 jakarta-struts/src/doc/release-notes-1.0-b2.xml
Index: release-notes-1.0-b2.xml
===================================================================
RCS file: /home/cvs/jakarta-struts/src/doc/release-notes-1.0-b2.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- release-notes-1.0-b2.xml 2001/03/10 23:27:53 1.4
+++ release-notes-1.0-b2.xml 2001/03/10 23:55:36 1.5
@@ -41,6 +41,10 @@
<li>The <code><html:image></code> tag now accepts an optional
<code>border</code> attribute, to define the border with around
this image.</li>
+ <li>You can now request that the <code><html:link></code> tag
+ include any current transaction control token in the generated
+ hyperlink, by specifying the <code>transaction</code> attribute
+ with a value of <code>true</code>.</li>
</ul>
<p>The following new features have been added to the
1.23 +17 -1 jakarta-struts/src/doc/struts-html.xml
Index: struts-html.xml
===================================================================
RCS file: /home/cvs/jakarta-struts/src/doc/struts-html.xml,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- struts-html.xml 2001/03/10 23:27:30 1.22
+++ struts-html.xml 2001/03/10 23:55:36 1.23
@@ -2042,7 +2042,11 @@
If a String array is specified, more than one value for the
same query parameter name will be created.</p>
- <p>You can also request that an anchor ("#xxx") be added to the
+ <p>Additionally, you can request that the current transaction
+ control token, if any, be included in the generated hyperlink
+ by setting the <code>transaction</code> attribute to
+ <code>true</code>.
+ You can also request that an anchor ("#xxx") be added to the
end of the URL that is created by any of the above mechanisms,
by using the <code>anchor</code> attribute.</p>
@@ -2374,6 +2378,18 @@
<p>The window target in which the resource requested by this
hyperlink will be displayed, for example in a framed
presentation.</p>
+ </info>
+ </attribute>
+
+ <attribute>
+ <name>transaction</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ <info>
+ <p>If set to <code>true</code>, any current transaction
+ control token will be included in the generated hyperlink,
+ so that it will pass an <code>isTokenValid()</code> test
+ in the receiving Action.</p>
</info>
</attribute>
1.6 +40 -4
jakarta-struts/src/share/org/apache/struts/taglib/html/LinkTag.java
Index: LinkTag.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/LinkTag.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- LinkTag.java 2001/03/06 17:00:50 1.5
+++ LinkTag.java 2001/03/10 23:55:38 1.6
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/LinkTag.java,v 1.5
2001/03/06 17:00:50 craigmcc Exp $
- * $Revision: 1.5 $
- * $Date: 2001/03/06 17:00:50 $
+ * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/LinkTag.java,v 1.6
2001/03/10 23:55:38 craigmcc Exp $
+ * $Revision: 1.6 $
+ * $Date: 2001/03/10 23:55:38 $
*
* ====================================================================
*
@@ -70,6 +70,7 @@
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
@@ -86,7 +87,7 @@
* Generate a URL-encoded hyperlink to the specified URI.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.5 $ $Date: 2001/03/06 17:00:50 $
+ * @version $Revision: 1.6 $ $Date: 2001/03/10 23:55:38 $
*/
public class LinkTag extends BaseHandlerTag {
@@ -285,6 +286,20 @@
}
+ /**
+ * Include transaction token (if any) in the hyperlink?
+ */
+ protected boolean transaction = false;
+
+ public boolean getTransaction() {
+ return (this.transaction);
+ }
+
+ public void setTransaction(boolean transaction) {
+ this.transaction = transaction;
+ }
+
+
// --------------------------------------------------------- Public Methods
@@ -399,6 +414,7 @@
property = null;
scope = null;
target = null;
+ transaction = false;
}
@@ -478,6 +494,26 @@
if (anchor == null)
anchor = href.substring(hash + 1);
href = href.substring(0, hash);
+ }
+
+ // Append the transaction token, if requested and it exists
+ if (transaction) {
+ HttpSession session = pageContext.getSession();
+ String token = null;
+ if (session != null)
+ token =
+ (String) session.getAttribute(Action.TRANSACTION_TOKEN_KEY);
+ if (token != null) {
+ StringBuffer sb = new StringBuffer(href);
+ if (href.indexOf('?') < 0)
+ sb.append('?');
+ else
+ sb.append('&');
+ sb.append(Constants.TOKEN_KEY);
+ sb.append('=');
+ sb.append(token);
+ href = sb.toString();
+ }
}
// Append a single-parameter name and value, if requested