craigmcc 2002/12/23 12:52:38
Modified: src/share/org/apache/struts/action DynaActionForm.java
src/share/org/apache/struts/util RequestUtils.java
Log:
WARNING: Backwards-incompatible patch being applied. Please review!
Commit a fix for 14669 ("reset() in DynaActionForm act the same as
ActionForm"), loosely based on the patch provided by Peter Pilgrim. Now,
the default reset() method of DynaActionForm does nothing, exactly like the
default reset() method of ActionForm. This should clean up lots of user
confusion about the differences between standard ActionForm beans and
DynaActionForm beans, even though it is not backwards compatible.
The logic to configure the properties of a DynaActionForm to the values
specified by the "initial" attribute on <form-property> elements has been
migrated to a new public method initialize() -- versus clear() as proposed
in Peter's patch. This method takes an ActionMapping argument, that is
used to look up the corresponding form bean definition. The method is
public so that it can be called by application logic if desired.
To ensure that a newly created DynaActionForm bean instance has correctly
initialized property values, the RequestUtils.createActionForm() factory method
has also been modified to call initialize() if it did indeed create a new
instance. Therefore, any logic that uses this factory method to create new
form bean instances (as Struts itself does in the only two places where form
bean instances are created by the framework) should not be affected by this
change.
Applications that call DynaActionFormClass.newInstance() will need to be
modified to call the initialize() method.
PR: Bugzilla #14669
Submitted by: Brian Topping <topping at digidemic.com>
Revision Changes Path
1.7 +55 -26
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DynaActionForm.java 6 Nov 2002 04:48:28 -0000 1.6
+++ DynaActionForm.java 23 Dec 2002 20:52:37 -0000 1.7
@@ -83,6 +83,13 @@
* of form beans with dynamic sets of properties, without requiring the
* developer to create a Java class for each type of form bean.</p>
*
+ * <p><strong>USAGE NOTE</strong> - Since Struts 1.1-b3, the
+ * <code>reset()</code> method no longer initializes property values to those
+ * specified in <code><form-property></code> elements in the Struts
+ * module configuration file. If you wish to utilize that behavior, the
+ * simplest solution is to subclass <code>DynaActionForm</code> and call
+ * the <code>initialize()</code> method inside it.</p>
+ *
* @author Craig R. McClanahan
* @version $Revision$ $Date$
* @since Struts 1.1
@@ -111,12 +118,41 @@
/**
- * Reset all bean properties to their default state. This method is
+ * <p>Initialize all bean properties to their initial values, as specified
+ * in the {@link FormPropertyConfig} elements associated with the
+ * definition of this <code>DynaActionForm</code>.</p>
+ *
+ * @param mapping The mapping used to select this instance
+ *
+ * @since Struts 1.1-b3
+ */
+ public void initialize(ActionMapping mapping) {
+
+ String name = mapping.getName();
+ if (name == null) {
+ return;
+ }
+ FormBeanConfig config =
+ mapping.getModuleConfig().findFormBeanConfig(name);
+ if (config == null) {
+ return;
+ }
+ FormPropertyConfig props[] = config.findFormPropertyConfigs();
+ for (int i = 0; i < props.length; i++) {
+ set(props[i].getName(), props[i].initial());
+ }
+
+ }
+
+
+
+ /**
+ * <p>Reset all bean properties to their default state. This method is
* called before the properties are repopulated by the controller
- * servlet.
- * <p>
- * The default implementation attempts to forward to the HTTP
- * version of this method.
+ * servlet.</p>
+ *
+ * <p>The default implementation attempts to forward to the HTTP
+ * version of this method.</p>
*
* @param mapping The mapping used to select this instance
* @param request The servlet request we are processing
@@ -133,30 +169,23 @@
/**
- * Reset all bean properties to their default state. This method is
+ * <p>Reset all bean properties to their default state. This method is
* called before the properties are repopulated by the controller servlet.
- * <p>
- * The default implementation uses the initial value specified in the
- * FormPropertyConfig element for each property.
+ * </p>
+ *
+ * <p>The default implementation (since Struts 1.1-b3) does nothing.
+ * Subclasses may override this method to reset bean properties to
+ * default values, or the <code>initialize()</code> method may be used to
+ * initialize property values to those provided in the form property
+ * configuration information (which was the previous behavior of
+ * this method).</p>
*
* @param mapping The mapping used to select this instance
* @param request The servlet request we are processing
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
- String name = mapping.getName();
- if (name == null) {
- return;
- }
- FormBeanConfig config =
- mapping.getModuleConfig().findFormBeanConfig(name);
- if (config == null) {
- return;
- }
- FormPropertyConfig props[] = config.findFormPropertyConfigs();
- for (int i = 0; i < props.length; i++) {
- set(props[i].getName(), props[i].initial());
- }
+ ; // Default implementation does nothing
}
1.75 +6 -4
jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java
Index: RequestUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -r1.74 -r1.75
--- RequestUtils.java 10 Dec 2002 06:03:21 -0000 1.74
+++ RequestUtils.java 23 Dec 2002 20:52:37 -0000 1.75
@@ -97,6 +97,7 @@
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.ActionServletWrapper;
+import org.apache.struts.action.DynaActionForm;
import org.apache.struts.action.DynaActionFormClass;
import org.apache.struts.action.RequestProcessor;
import org.apache.struts.config.ActionConfig;
@@ -600,6 +601,7 @@
DynaActionFormClass dynaClass =
DynaActionFormClass.createDynaActionFormClass(config);
instance = (ActionForm) dynaClass.newInstance();
+ ((DynaActionForm) instance).initialize(mapping);
if (log.isDebugEnabled()) {
log.debug(
" Creating new DynaActionForm instance "
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>