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/06/22 21:23:43 UTC
cvs commit: jakarta-struts/web/example logon.jsp subscription.jsp
craigmcc 00/06/22 12:23:42
Modified: src/conf struts.tld
src/share/org/apache/struts/taglib FormTag.java
web/documentation tags.html
web/example logon.jsp subscription.jsp
Log:
Add an optional "focus" attribute to the <struts:form> tag that lets you
identify which input field should receive focus when the form is
displayed. For example, the form on the logon.jsp page is now:
<struts:form name="logonForm" focus="username"
type="org.apache.struts.example.LogonForm">
and the cursor will already be in the username field when this form is
displayed.
If you have more than one form on the same page, you should use the focus
attribute on only one of them.
Thanks to David Geary for the idea!
Revision Changes Path
1.12 +5 -0 jakarta-struts/src/conf/struts.tld
Index: struts.tld
===================================================================
RCS file: /home/cvs/jakarta-struts/src/conf/struts.tld,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- struts.tld 2000/06/20 20:05:46 1.11
+++ struts.tld 2000/06/22 19:23:33 1.12
@@ -225,6 +225,11 @@
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
+ <name>focus</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
+ <attribute>
<name>method</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
1.4 +47 -4 jakarta-struts/src/share/org/apache/struts/taglib/FormTag.java
Index: FormTag.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/FormTag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FormTag.java 2000/06/15 18:15:17 1.3
+++ FormTag.java 2000/06/22 19:23:35 1.4
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/FormTag.java,v 1.3 2000/06/15 18:15:17 craigmcc Exp $
- * $Revision: 1.3 $
- * $Date: 2000/06/15 18:15:17 $
+ * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/FormTag.java,v 1.4 2000/06/22 19:23:35 craigmcc Exp $
+ * $Revision: 1.4 $
+ * $Date: 2000/06/22 19:23:35 $
*
* ====================================================================
*
@@ -78,7 +78,7 @@
* properties correspond to the various fields of the form.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.3 $ $Date: 2000/06/15 18:15:17 $
+ * @version $Revision: 1.4 $ $Date: 2000/06/22 19:23:35 $
*/
public final class FormTag extends TagSupport {
@@ -94,6 +94,12 @@
/**
+ * The name of the field to receive focus, if any.
+ */
+ private String focus = null;
+
+
+ /**
* The message resources for this package.
*/
protected static MessageResources messages =
@@ -170,6 +176,28 @@
/**
+ * Return the focus field name for this form.
+ */
+ public String getFocus() {
+
+ return (this.focus);
+
+ }
+
+
+ /**
+ * Set the focus field name for this form.
+ *
+ * @param focus The new focus field name
+ */
+ public void setFocus(String focus) {
+
+ this.focus = focus;
+
+ }
+
+
+ /**
* Return the request method used when submitting this form.
*/
public String getMethod() {
@@ -337,6 +365,9 @@
HttpServletResponse response =
(HttpServletResponse) pageContext.getResponse();
StringBuffer results = new StringBuffer("<form");
+ results.append(" name=\"");
+ results.append(name);
+ results.append("\"");
results.append(" method=\"");
results.append(method);
results.append("\"");
@@ -415,6 +446,18 @@
// Render a tag representing the end of our current form
StringBuffer results = new StringBuffer("</form>");
+ if (focus != null) {
+ results.append("\r\n");
+ results.append("<script language=\"JavaScript\">\r\n");
+ results.append(" <!--\r\n");
+ results.append(" document.");
+ results.append(name);
+ results.append(".");
+ results.append(focus);
+ results.append(".focus()\r\n");
+ results.append(" // -->\r\n");
+ results.append("</script>\r\n");
+ }
// Print this value to our output writer
JspWriter writer = pageContext.getOut();
1.10 +8 -0 jakarta-struts/web/documentation/tags.html
Index: tags.html
===================================================================
RCS file: /home/cvs/jakarta-struts/web/documentation/tags.html,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- tags.html 2000/06/20 20:06:04 1.9
+++ tags.html 2000/06/22 19:23:37 1.10
@@ -533,6 +533,14 @@
</td>
</tr>
<tr>
+ <td align="center">focus</td>
+ <td>
+ The field name (among the fields on this form) to which initial focus
+ will be assigned with a JavaScript function. If not specified, no
+ special JavaScript for this purpose will be rendered.
+ </td>
+ </tr>
+ <tr>
<td align="center">method</td>
<td>
The HTTP method that will be used to submit this request (GET, POST).
1.3 +1 -1 jakarta-struts/web/example/logon.jsp
Index: logon.jsp
===================================================================
RCS file: /home/cvs/jakarta-struts/web/example/logon.jsp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- logon.jsp 2000/06/16 04:41:12 1.2
+++ logon.jsp 2000/06/22 19:23:38 1.3
@@ -9,7 +9,7 @@
<struts:errors/>
-<struts:form action="logon.do" name="logonForm"
+<struts:form action="logon.do" name="logonForm" focus="username"
type="org.apache.struts.example.LogonForm">
<table border="0" width="100%">
1.6 +1 -0 jakarta-struts/web/example/subscription.jsp
Index: subscription.jsp
===================================================================
RCS file: /home/cvs/jakarta-struts/web/example/subscription.jsp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- subscription.jsp 2000/06/20 20:06:08 1.5
+++ subscription.jsp 2000/06/22 19:23:39 1.6
@@ -22,6 +22,7 @@
<struts:errors/>
<struts:form action="saveSubscription.do" name="subscriptionForm"
+ focus="host"
type="org.apache.struts.example.SubscriptionForm">
<struts:hidden property="action"/>
<table border="0" width="100%">