You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@locus.apache.org on 2000/11/18 23:11:58 UTC
cvs commit: jakarta-struts/web/example/WEB-INF app.tld
craigmcc 00/11/18 14:11:58
Modified: src/doc struts-form.xml
src/example/org/apache/struts/example
LinkSubscriptionTag.java LinkUserTag.java
web/example index.jsp mainMenu.jsp registration.jsp
web/example/WEB-INF app.tld
Log:
Convert the example application to use the new "page" attribute of the
<form:link> tag, so that all URI references can be context relative
starting with a "/". Make the corresponding change to the application
specific linkSubscription and linkUser tags.
Revision Changes Path
1.8 +38 -6 jakarta-struts/src/doc/struts-form.xml
Index: struts-form.xml
===================================================================
RCS file: /home/cvs/jakarta-struts/src/doc/struts-form.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- struts-form.xml 2000/11/18 19:50:26 1.7
+++ struts-form.xml 2000/11/18 22:11:55 1.8
@@ -1165,8 +1165,22 @@
absence of cookies. The content displayed for this
hyperlink will be taken from the body of this tag.</p>
- <p>Normally, the hyperlink you specify with the
- <code>forward</code> or <code>href</code> attribute will be
+ <p>The base URL for this hyperlink is calculated based on
+ which of the following attributes you specify (you must
+ specify exactly one of them):</p>
+ <ul>
+ <li><em>forward</em> - Use the value of this attribute as the
+ name of a global <code>ActionForward</code> to be looked
+ up, and use the context-relative URI found there.</li>
+ <li><em>href</em> - Use the value of this attribute unchanged.
+ </li>
+ <li><em>page</em> - Use the value of this attribute as a
+ context-relative URI, and generate a server-relative URI
+ by including the context path.</li>
+ </ul>
+
+ <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,
you can also specify instructions for locating a
<code>Map</code> implementation that defines query parameters
@@ -1202,8 +1216,9 @@
of this transfer. This hyperlink may be dynamically
modified by the inclusion of query parameters, as described
in the tag description. You <strong>must</strong> specify
- either the <code>forward</code> attribute or the
- <code>href</code> attribute.</p>
+ exactly one of the <code>forward</code> attribute, the
+ <code>href</code> attribute, or the <code>page</code>
+ attribute.</p>
</info>
</attribute>
@@ -1216,8 +1231,25 @@
if activated. This hyperlink may be dynamically modified
by the inclusion of query parameters, as described in the
tag description. You <strong>must</strong> specify
- either the <code>forward</code> attribute or the
- <code>href</code> attribute.</p>
+ exactly one of the <code>forward</code> attribute, the
+ <code>href</code> attribute, or the <code>page</code>
+ attribute.</p>
+ </info>
+ </attribute>
+
+ <attribute>
+ <name>page</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ <info>
+ <p>The context-relative path (beginning with a "/"
+ character) to which this hyperlink will transfer control
+ if activated. This hyperlink may be dynamically modified
+ by the inclusion of query parameters, as described in the
+ tag description. You <strong>must</strong> specify exactly
+ one of the <code>forward</code> attribute, the
+ <code>href</code> attribute, or the <code>page</code>
+ attribute.</p>
</info>
</attribute>
1.3 +19 -15 jakarta-struts/src/example/org/apache/struts/example/LinkSubscriptionTag.java
Index: LinkSubscriptionTag.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/LinkSubscriptionTag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LinkSubscriptionTag.java 2000/08/01 20:03:23 1.2
+++ LinkSubscriptionTag.java 2000/11/18 22:11:56 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/LinkSubscriptionTag.java,v 1.2 2000/08/01 20:03:23 craigmcc Exp $
- * $Revision: 1.2 $
- * $Date: 2000/08/01 20:03:23 $
+ * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/LinkSubscriptionTag.java,v 1.3 2000/11/18 22:11:56 craigmcc Exp $
+ * $Revision: 1.3 $
+ * $Date: 2000/11/18 22:11:56 $
*
* ====================================================================
*
@@ -64,6 +64,7 @@
import java.io.IOException;
+import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
@@ -78,7 +79,7 @@
* associated query parameters selecting a specified Subscription.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.2 $ $Date: 2000/08/01 20:03:23 $
+ * @version $Revision: 1.3 $ $Date: 2000/11/18 22:11:56 $
*/
public class LinkSubscriptionTag extends TagSupport {
@@ -88,9 +89,9 @@
/**
- * The hyperlink URI.
+ * The context-relative URI.
*/
- protected String href = null;
+ protected String page = null;
/**
@@ -111,23 +112,23 @@
/**
- * Return the hyperlink URI.
+ * Return the context-relative URI.
*/
- public String getHref() {
+ public String getPage() {
- return (this.href);
+ return (this.page);
}
/**
- * Set the hyperlink URI.
+ * Set the context-relative URI.
*
- * @param href Set the hyperlink URI
+ * @param page Set the context-relative URI
*/
- public void setHref(String href) {
+ public void setPage(String page) {
- this.href = href;
+ this.page = page;
}
@@ -165,7 +166,10 @@
public int doStartTag() throws JspException {
// Generate the URL to be encoded
- StringBuffer url = new StringBuffer(href);
+ HttpServletRequest request =
+ (HttpServletRequest) pageContext.getRequest();
+ StringBuffer url = new StringBuffer(request.getContextPath());
+ url.append(page);
Subscription subscription = null;
try {
subscription = (Subscription) pageContext.findAttribute(name);
@@ -175,7 +179,7 @@
if (subscription == null)
throw new JspException
(messages.getMessage("linkSubscription.noSubscription", name));
- if (href.indexOf("?") < 0)
+ if (page.indexOf("?") < 0)
url.append("?");
else
url.append("&");
1.3 +16 -12 jakarta-struts/src/example/org/apache/struts/example/LinkUserTag.java
Index: LinkUserTag.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/LinkUserTag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LinkUserTag.java 2000/08/01 20:03:23 1.2
+++ LinkUserTag.java 2000/11/18 22:11:56 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/LinkUserTag.java,v 1.2 2000/08/01 20:03:23 craigmcc Exp $
- * $Revision: 1.2 $
- * $Date: 2000/08/01 20:03:23 $
+ * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/LinkUserTag.java,v 1.3 2000/11/18 22:11:56 craigmcc Exp $
+ * $Revision: 1.3 $
+ * $Date: 2000/11/18 22:11:56 $
*
* ====================================================================
*
@@ -64,6 +64,7 @@
import java.io.IOException;
+import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
@@ -78,7 +79,7 @@
* associated query parameters selecting a specified User.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.2 $ $Date: 2000/08/01 20:03:23 $
+ * @version $Revision: 1.3 $ $Date: 2000/11/18 22:11:56 $
*/
public class LinkUserTag extends TagSupport {
@@ -90,7 +91,7 @@
/**
* The hyperlink URI.
*/
- protected String href = null;
+ protected String page = null;
/**
@@ -113,9 +114,9 @@
/**
* Return the hyperlink URI.
*/
- public String getHref() {
+ public String getPage() {
- return (this.href);
+ return (this.page);
}
@@ -123,11 +124,11 @@
/**
* Set the hyperlink URI.
*
- * @param href Set the hyperlink URI
+ * @param page Set the hyperlink URI
*/
- public void setHref(String href) {
+ public void setPage(String page) {
- this.href = href;
+ this.page = page;
}
@@ -165,7 +166,10 @@
public int doStartTag() throws JspException {
// Generate the URL to be encoded
- StringBuffer url = new StringBuffer(href);
+ HttpServletRequest request =
+ (HttpServletRequest) pageContext.getRequest();
+ StringBuffer url = new StringBuffer(request.getContextPath());
+ url.append(page);
User user = null;
try {
user = (User) pageContext.findAttribute(name);
@@ -175,7 +179,7 @@
if (user == null)
throw new JspException
(messages.getMessage("linkUser.noUser", name));
- if (href.indexOf("?") < 0)
+ if (page.indexOf("?") < 0)
url.append("?");
else
url.append("&");
1.8 +2 -2 jakarta-struts/web/example/index.jsp
Index: index.jsp
===================================================================
RCS file: /home/cvs/jakarta-struts/web/example/index.jsp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- index.jsp 2000/11/18 19:50:31 1.7
+++ index.jsp 2000/11/18 22:11:56 1.8
@@ -27,8 +27,8 @@
<h3><bean:message key="index.heading"/></h3>
<ul>
-<li><form:link href="editRegistration.do?action=Create"><bean:message key="index.registration"/></form:link></li>
-<li><form:link href="logon.jsp"><bean:message key="index.logon"/></form:link></li>
+<li><form:link page="/editRegistration.do?action=Create"><bean:message key="index.registration"/></form:link></li>
+<li><form:link page="/logon.jsp"><bean:message key="index.logon"/></form:link></li>
</ul>
</body>
1.7 +2 -2 jakarta-struts/web/example/mainMenu.jsp
Index: mainMenu.jsp
===================================================================
RCS file: /home/cvs/jakarta-struts/web/example/mainMenu.jsp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- mainMenu.jsp 2000/11/18 19:50:34 1.6
+++ mainMenu.jsp 2000/11/18 22:11:57 1.7
@@ -15,8 +15,8 @@
<h3><bean:message key="mainMenu.heading"/>
<jsp:getProperty name="user" property="username"/></h3>
<ul>
-<li><form:link href="editRegistration.do?action=Edit"><bean:message key="mainMenu.registration"/></form:link></li>
-<li><form:link href="logoff.do"><bean:message key="mainMenu.logoff"/></form:link></li>
+<li><form:link page="/editRegistration.do?action=Edit"><bean:message key="mainMenu.registration"/></form:link></li>
+<li><form:link page="/logoff.do"><bean:message key="mainMenu.logoff"/></form:link></li>
</ul>
</body>
1.12 +3 -3 jakarta-struts/web/example/registration.jsp
Index: registration.jsp
===================================================================
RCS file: /home/cvs/jakarta-struts/web/example/registration.jsp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- registration.jsp 2000/11/18 19:50:34 1.11
+++ registration.jsp 2000/11/18 22:11:57 1.12
@@ -154,10 +154,10 @@
<bean:write name="subscription" property="autoConnect"/>
</td>
<td align="center">
- <app:linkSubscription href="editSubscription.do?action=Delete">
+ <app:linkSubscription page="/editSubscription.do?action=Delete">
<bean:message key="registration.deleteSubscription"/>
</app:linkSubscription>
- <app:linkSubscription href="editSubscription.do?action=Edit">
+ <app:linkSubscription page="/editSubscription.do?action=Edit">
<bean:message key="registration.editSubscription"/>
</app:linkSubscription>
</td>
@@ -166,7 +166,7 @@
</table>
-<app:linkUser href="editSubscription.do?action=Create">
+<app:linkUser page="/editSubscription.do?action=Create">
<bean:message key="registration.addSubscription"/>
</app:linkUser>
1.4 +14 -14 jakarta-struts/web/example/WEB-INF/app.tld
Index: app.tld
===================================================================
RCS file: /home/cvs/jakarta-struts/web/example/WEB-INF/app.tld,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- app.tld 2000/06/29 21:36:13 1.3
+++ app.tld 2000/11/18 22:11:57 1.4
@@ -49,20 +49,20 @@
Generate a URL-encoded hyperlink to the a URL made up of the
specified base value, plus optional query parameters that
select the specified Subscription object.
-
- href - Base URL of the generated link
-
+
name - Name of the attribute containing the specified
Subscription. [subscription]
+
+ page - Context-relative URL of the generated link
</info>
<attribute>
- <name>href</name>
- <required>true</required>
+ <name>name</name>
+ <required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
- <name>name</name>
- <required>false</required>
+ <name>page</name>
+ <required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
@@ -75,20 +75,20 @@
Generate a URL-encoded hyperlink to the a URL made up of the
specified base value, plus optional query parameters that
select the specified User object.
-
- href - Base URL of the generated link
-
+
name - Name of the attribute containing the specified user.
[user]
+
+ href - Context-relative URL of the generated link
</info>
<attribute>
- <name>href</name>
- <required>true</required>
+ <name>name</name>
+ <required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
- <name>name</name>
- <required>false</required>
+ <name>page</name>
+ <required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>