You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by dm...@apache.org on 2002/11/01 05:54:47 UTC
cvs commit: jakarta-struts/src/share/org/apache/struts/action DynaActionForm.java
dmkarr 2002/10/31 20:54:47
Modified: contrib/struts-el/web/exercise-taglib index.jsp
contrib/struts-el/web/exercise-taglib/WEB-INF
struts-config.xml
doc/userGuide building_controller.xml
src/share/org/apache/struts/action DynaActionForm.java
Added: contrib/struts-el/src/exercise-taglib/org/apache/struts/webapp/exercise
DynaSetAction.java
contrib/struts-el/web/exercise-taglib bean-dyna.jsp
Log:
Added "getMap()" method to DynaActionForm. javadoc comment shows example of
JSTL EL usage.
Added a couple of paragraphs to the DynaActionForm section in the user guide explaining this feature.
Added new page to strutsel-exercise-taglib demonstrating this feature.
PR: 14116
Revision Changes Path
1.1 jakarta-struts/contrib/struts-el/src/exercise-taglib/org/apache/struts/webapp/exercise/DynaSetAction.java
Index: DynaSetAction.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/contrib/struts-el/src/exercise-taglib/org/apache/struts/webapp/exercise/DynaSetAction.java,v 1.1 2002/11/01 04:54:47 dmkarr Exp $
* $Revision: 1.1 $
* $Date: 2002/11/01 04:54:47 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.webapp.exercise;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
public class DynaSetAction extends Action
{
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
DynaActionForm dynaActionForm = (DynaActionForm) form;
dynaActionForm.set("foo", "alpha");
dynaActionForm.set("bar", "beta");
return (mapping.findForward("success"));
}
}
1.6 +11 -0 jakarta-struts/contrib/struts-el/web/exercise-taglib/index.jsp
Index: index.jsp
===================================================================
RCS file: /home/cvs/jakarta-struts/contrib/struts-el/web/exercise-taglib/index.jsp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- index.jsp 26 Oct 2002 04:33:17 -0000 1.5
+++ index.jsp 1 Nov 2002 04:54:47 -0000 1.6
@@ -1,4 +1,6 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<%@ page language="java" %>
+<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<html>
<head>
<title>Struts-EL Test Application</title>
@@ -50,6 +52,15 @@
<ul>
<li><a href="logic-compare.jsp">Comparison Tags</a>[<a href="showSource.jsp?path=/logic-compare.jsp">Source</a>]</li>
<li><a href="logic-empty.jsp">Emptiness Tags</a>[<a href="showSource.jsp?path=/logic-empty.jsp">Source</a>]</li>
+</ul>
+
+<h2>Other Testable Features</h2>
+<ul>
+ <li>
+ <html-el:link page="/bean-dyna.do">
+ DynaActionForm References in EL[<a href="showSource.jsp?path=/bean-dyna.jsp">Source</a>]
+ </html-el:link>
+ </li>
</ul>
</body>
</html>
1.1 jakarta-struts/contrib/struts-el/web/exercise-taglib/bean-dyna.jsp
Index: bean-dyna.jsp
===================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<html-el:html>
<head>
<title>
Testing access of DynaActionForms through JSTL/Struts-EL
</title>
</head>
<body bgcolor="white">
<div align="center">
<h1>Test access of DynaActionForms through JSTL/Struts-EL</h1>
</div>
<table border="1">
<tr>
<th>Property</th>
<th>bean:write reference</th>
<th>c:out reference</th>
</tr>
<tr>
<td>foo</td>
<td><bean:write name="dynabean" property="foo"/></td>
<td><c:out value="${dynabean.map.foo}"/></td>
</tr>
<tr>
<td>bar</td>
<td><bean:write name="dynabean" property="bar"/></td>
<td><c:out value="${dynabean.map.bar}"/></td>
</tr>
<tr>
<td>thing</td>
<td>
<c:catch var="ex">
<%-- This will throw an exception, as the "thing" property is not
defined.
--%>
<bean:write name="dynabean" property="thing"/>
</c:catch>
<c:if test="${!empty ex}">
<exception>
</c:if>
</td>
<%-- This will just return an empty string --%>
<td><c:out value="${dynabean.map.thing}" default="<empty>"/></td>
</tr>
</table>
</body>
</html-el:html>
1.4 +12 -1 jakarta-struts/contrib/struts-el/web/exercise-taglib/WEB-INF/struts-config.xml
Index: struts-config.xml
===================================================================
RCS file: /home/cvs/jakarta-struts/contrib/struts-el/web/exercise-taglib/WEB-INF/struts-config.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- struts-config.xml 14 Oct 2002 03:25:42 -0000 1.3
+++ struts-config.xml 1 Nov 2002 04:54:47 -0000 1.4
@@ -9,6 +9,10 @@
<form-beans>
<form-bean name="testbean"
type="org.apache.struts.webapp.exercise.TestBean"/>
+ <form-bean name="dynabean" type="org.apache.struts.action.DynaActionForm">
+ <form-property name="foo" type="java.lang.String"/>
+ <form-property name="bar" type="java.lang.String"/>
+ </form-bean>
</form-beans>
<global-forwards>
@@ -84,7 +88,14 @@
name="testbean"
scope="session"
validate="false">
- <forward name="input" path="/html-setters.jsp"/>
+ <forward name="input" path="/bean-dyna.jsp"/>
+ </action>
+ <action path="/bean-dyna"
+ type="org.apache.struts.webapp.exercise.DynaSetAction"
+ name="dynabean"
+ scope="session"
+ validate="false">
+ <forward name="success" path="/bean-dyna.jsp"/>
</action>
</action-mappings>
1.44 +29 -6 jakarta-struts/doc/userGuide/building_controller.xml
Index: building_controller.xml
===================================================================
RCS file: /home/cvs/jakarta-struts/doc/userGuide/building_controller.xml,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- building_controller.xml 29 Oct 2002 05:00:14 -0000 1.43
+++ building_controller.xml 1 Nov 2002 04:54:47 -0000 1.44
@@ -71,12 +71,15 @@
href="./building_view.html#form_validation">Action Form Validation</a>"
for details. Of course, you can also ignore the ActionForm validation
and provide your own in the Action object.</li>
+
<li>Define a property (with associated <code>getXxx</code> and
- <code>setXxx</code> methods) for each field that is present
- in the form. The field name and property name must match according
- to the usual JavaBeans conventions. For example, an input field named
- <code>username</code> will cause the <code>setUsername</code> method
- to be called.</li>
+ <code>setXxx</code> methods) for each field that is present in the
+ form. The field name and property name must match according to the
+ usual JavaBeans conventions (see the javadoc for the
+ <code>java.beans.Introspector</code> class for a start on information
+ about this). For example, an input field named <code>username</code>
+ will cause the <code>setUsername</code> method to be called.</li>
+
<li>Buttons and other controls on your form can also be defined as properties.
This can help determine which button or control was selected when the
form was submitted. Remember, the ActionForm is meant to represent your
@@ -130,7 +133,27 @@
<li>java.sql.Time</li>
<li>java.sql.Timestamp</li>
</ul>
- <p>If you do not supply an initial attribute, numbers will be initialized to 0 and objects to null.</p>
+ <p>If you do not supply an initial attribute, numbers will be initialized
+ to 0 and objects to null.</p>
+ <p>In JSP pages using Struts custom tags, attributes of
+ <code>DynaActionForm</code> objects can be referenced just like ordinary
+ <code>ActionForm</code> objects. However, when utilizing the JavaServer
+ Pages Standard Tag Library, only properties of ordinary
+ <code>ActionForm</code> objects can be directly accessed through the JSTL
+ expression language syntax. However, <code>DynaActionForm</code>
+ properties can be accessed through a slightly different syntax.</p>
+ <p>In particular, whereas the JSTL EL syntax for referencing a property
+ of an <code>ActionForm</code> would be something like:</p>
+ <pre>
+ ${formbean.prop}</pre>
+ <p>The syntax for referencing a property of a <code>DynaActionForm</code>
+ would be:</p>
+ <pre>
+ ${dynabean.map.prop}</pre>
+ <p>The <code>map</code> property is a property of
+ <code>DynaActionForm</code> which represents the <code>HashMap</code>
+ containing the <code>DynaActionForm</code> properties.</p>
+
</section>
<section name="4.2.2 Map-backed ActionForms" href="map_action_form_classes">
1.5 +26 -4 jakarta-struts/src/share/org/apache/struts/action/DynaActionForm.java
Index: DynaActionForm.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/DynaActionForm.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DynaActionForm.java 27 Oct 2002 06:10:59 -0000 1.4
+++ DynaActionForm.java 1 Nov 2002 04:54:47 -0000 1.5
@@ -313,6 +313,28 @@
}
+ /**
+ * Returns the <code>Map</code> containing the property values. This is
+ * done mostly to facilitate accessing the <code>DynaActionForm</code>
+ * through JavaBeans accessors, in order to use the JavaServer Pages
+ * Standard Tag Library.
+ *<p>
+ * For instance, the normal JSTL EL syntax for accessing an
+ * <code>ActionForm</code> would be something like this:
+ * <pre>
+ * ${formbean.prop}</pre>
+ * The JSTL EL syntax for accessing a <code>DynaActionForm</code> looks
+ * something like this (because of the presence of this
+ * <code>getMap()</code> method):
+ * <pre>
+ * ${dynabean.map.prop}</pre>
+ */
+ public Map getMap() {
+
+ return (dynaValues);
+
+ }
+
/**
* Remove any existing value for the specified key on the
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>