You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by ni...@apache.org on 2006/11/09 02:10:59 UTC

svn commit: r472728 - in /struts/struts1/trunk: apps/examples/src/main/webapp/WEB-INF/validator/struts-config-bundles.xml core/src/main/java/org/apache/struts/config/FormBeanConfig.java core/src/main/java/org/apache/struts/validator/BeanValidatorForm.java

Author: niallp
Date: Wed Nov  8 17:10:58 2006
New Revision: 472728

URL: http://svn.apache.org/viewvc?view=rev&rev=472728
Log:
Fix for STR-2972 - LazyValidatorForm cannot be saved in the session - reported by Stuart Goldberg.
(also switched the validator "bundles" example to use LazyValidtorForm in session scope to be able to test)

Modified:
    struts/struts1/trunk/apps/examples/src/main/webapp/WEB-INF/validator/struts-config-bundles.xml
    struts/struts1/trunk/core/src/main/java/org/apache/struts/config/FormBeanConfig.java
    struts/struts1/trunk/core/src/main/java/org/apache/struts/validator/BeanValidatorForm.java

Modified: struts/struts1/trunk/apps/examples/src/main/webapp/WEB-INF/validator/struts-config-bundles.xml
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/apps/examples/src/main/webapp/WEB-INF/validator/struts-config-bundles.xml?view=diff&rev=472728&r1=472727&r2=472728
==============================================================================
--- struts/struts1/trunk/apps/examples/src/main/webapp/WEB-INF/validator/struts-config-bundles.xml (original)
+++ struts/struts1/trunk/apps/examples/src/main/webapp/WEB-INF/validator/struts-config-bundles.xml Wed Nov  8 17:10:58 2006
@@ -7,7 +7,7 @@
   <!--============================================== Form Bean Definitions  -->
   <form-beans>
 
-    <form-bean name="bundlesForm" type="org.apache.struts.validator.DynaValidatorForm">
+    <form-bean name="bundlesForm" type="org.apache.struts.validator.LazyValidatorForm">
         <form-property name="name"    type="java.lang.String" />
         <form-property name="address" type="java.lang.String" />
         <form-property name="phone"   type="java.lang.String" />
@@ -26,7 +26,7 @@
     <action path="/validateBundleExamples" 
             type="org.apache.struts.actions.ForwardAction" 
             name="bundlesForm" 
-            scope="request" 
+            scope="session" 
             parameter="/welcome.do" 
             validate="true"
             cancellable="true"
@@ -40,7 +40,7 @@
     <action path="/validateJsBundleExamples" 
             type="org.apache.struts.actions.ForwardAction" 
             name="bundlesForm" 
-            scope="request" 
+            scope="session" 
             parameter="/welcome.do" 
             validate="true"
             cancellable="true"

Modified: struts/struts1/trunk/core/src/main/java/org/apache/struts/config/FormBeanConfig.java
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/config/FormBeanConfig.java?view=diff&rev=472728&r1=472727&r2=472728
==============================================================================
--- struts/struts1/trunk/core/src/main/java/org/apache/struts/config/FormBeanConfig.java (original)
+++ struts/struts1/trunk/core/src/main/java/org/apache/struts/config/FormBeanConfig.java Wed Nov  8 17:10:58 2006
@@ -318,6 +318,10 @@
             dynaClass.setRestricted(isRestricted());
         }
 
+        if (form instanceof BeanValidatorForm) {
+            ((BeanValidatorForm)form).initialize(this);
+        }
+
         return form;
     }
 
@@ -379,11 +383,18 @@
                     Class formClass = form.getClass();
 
                     if (form instanceof BeanValidatorForm) {
-                        // what we really want is to compare against the
-                        //  BeanValidatorForm's getInstance()
                         BeanValidatorForm beanValidatorForm =
                             (BeanValidatorForm) form;
 
+                        if (beanValidatorForm.getInstance() instanceof DynaBean) {
+                            String formName = beanValidatorForm.getStrutsConfigFormName();
+                            if (getName().equals(formName)) {
+                                log.debug("Can reuse existing instance (BeanValidatorForm)");
+                                return true;
+                            } else {
+                                return false;
+                            }
+                        }
                         formClass = beanValidatorForm.getInstance().getClass();
                     }
 

Modified: struts/struts1/trunk/core/src/main/java/org/apache/struts/validator/BeanValidatorForm.java
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/validator/BeanValidatorForm.java?view=diff&rev=472728&r1=472727&r2=472728
==============================================================================
--- struts/struts1/trunk/core/src/main/java/org/apache/struts/validator/BeanValidatorForm.java (original)
+++ struts/struts1/trunk/core/src/main/java/org/apache/struts/validator/BeanValidatorForm.java Wed Nov  8 17:10:58 2006
@@ -27,6 +27,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.struts.action.ActionMapping;
+import org.apache.struts.config.FormBeanConfig;
 
 import javax.servlet.http.HttpServletRequest;
 
@@ -75,6 +76,11 @@
      */
     protected boolean pathValidation = false;
 
+    /**
+     * The name used to identify the ActionForm in the struts-config.xml
+     */
+    private String strutsConfigFormName;
+
     // ------------------- Constructor ----------------------------------
 
     /**
@@ -108,6 +114,26 @@
     }
 
     // ------------------- Public Methods ----------------------------------
+
+    /**
+     * <p>Perform intialization of the ActionForm.</p>
+     * <p>This method is called when the form is created.</p>
+     *
+     * @since Struts 1.3.6
+     */
+    public void initialize(FormBeanConfig formBeanConfig) {
+        strutsConfigFormName = formBeanConfig.getName();
+    }
+
+    /**
+     * Return name used to identify the ActionForm in the
+     * struts-config.xml.
+     *
+     * @since Struts 1.3.6
+     */
+    public String getStrutsConfigFormName() {
+        return strutsConfigFormName;
+    }
 
     /**
      * <p>Return the <code>DynaBean</code> that this <code>ActionForm</code>