struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tm...@apache.org
Subject svn commit: r406273 - in /struts/action2/trunk/core/src: main/java/org/apache/struts/action2/components/ main/resources/template/xhtml/ test/java/org/apache/struts/action2/views/jsp/ui/ test/resources/org/apache/struts/action2/views/jsp/ui/
Date Sun, 14 May 2006 06:25:20 GMT
Author: tmjee
Date: Sat May 13 23:25:18 2006
New Revision: 406273

URL: http://svn.apache.org/viewcvs?rev=406273&view=rev
Log:
WW-1284


Added:
    struts/action2/trunk/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/Formtag-11.txt
  (with props)
Modified:
    struts/action2/trunk/core/src/main/java/org/apache/struts/action2/components/Form.java
    struts/action2/trunk/core/src/main/java/org/apache/struts/action2/components/UIBean.java
    struts/action2/trunk/core/src/main/resources/template/xhtml/form-close-validate.ftl
    struts/action2/trunk/core/src/test/java/org/apache/struts/action2/views/jsp/ui/FormTagTest.java
    struts/action2/trunk/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/Formtag-2.txt

Modified: struts/action2/trunk/core/src/main/java/org/apache/struts/action2/components/Form.java
URL: http://svn.apache.org/viewcvs/struts/action2/trunk/core/src/main/java/org/apache/struts/action2/components/Form.java?rev=406273&r1=406272&r2=406273&view=diff
==============================================================================
--- struts/action2/trunk/core/src/main/java/org/apache/struts/action2/components/Form.java
(original)
+++ struts/action2/trunk/core/src/main/java/org/apache/struts/action2/components/Form.java
Sat May 13 23:25:18 2006
@@ -24,11 +24,14 @@
 import org.apache.struts.action2.portlet.util.PortletUrlHelper;
 import org.apache.struts.action2.views.util.UrlHelper;
 import com.opensymphony.xwork.config.ConfigurationManager;
+import com.opensymphony.xwork.config.RuntimeConfiguration;
 import com.opensymphony.xwork.config.entities.ActionConfig;
+import com.opensymphony.xwork.config.entities.InterceptorMapping;
 import com.opensymphony.xwork.util.OgnlValueStack;
 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.ActionInvocation;
 import com.opensymphony.xwork.ObjectFactory;
+import com.opensymphony.xwork.validator.ValidationInterceptor;
 import com.opensymphony.xwork.validator.Validator;
 import com.opensymphony.xwork.validator.FieldValidator;
 import com.opensymphony.xwork.validator.ActionValidatorManagerFactory;
@@ -38,10 +41,13 @@
 
 import org.apache.commons.lang.StringUtils;
 
+import com.opensymphony.xwork.interceptor.MethodFilterInterceptorUtil;
+
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Collections;
 import java.util.Iterator;
+import java.util.Set;
 
 /**
  * <!-- START SNIPPET: javadoc -->
@@ -126,6 +132,10 @@
 
         boolean isAjax = "ajax".equalsIgnoreCase(this.theme);
 
+        if (validate != null) {
+            addParameter("validate", findValue(validate, Boolean.class));
+        }
+        
         // calculate the action and namespace
         String action = null;
         if (this.action != null) {
@@ -157,10 +167,6 @@
             addParameter("method", findString(method));
         }
 
-        if (validate != null) {
-            addParameter("validate", findValue(validate, Boolean.class));
-        }
-
         if (acceptcharset != null) {
             addParameter("acceptcharset", findString(acceptcharset));
         }
@@ -256,6 +262,42 @@
                 addParameter("id", escape(id));
             }
         }
+        
+        // WW-1284
+        // evaluate if client-side js is to be enabled. (if validation interceptor 
+        // does allow validation eg. method is not filtered out)
+        evaluateClientSideJsEnablement(actionName, namespace, actionMethod);
+    }
+    
+    private void evaluateClientSideJsEnablement(String actionName, String namespace, String
actionMethod) {
+    	
+    	// Only evaluate if Client-Side js is to be enable when validate=true
+    	Boolean validate = (Boolean) getParameters().get("validate");
+    	if (validate != null && validate.booleanValue()) {
+    	
+    		addParameter("performValidation", Boolean.FALSE);
+    	
+    		RuntimeConfiguration runtimeConfiguration = ConfigurationManager.getConfiguration().getRuntimeConfiguration();
+    		ActionConfig actionConfig = runtimeConfiguration.getActionConfig(namespace, actionName);
+
+    		if (actionConfig != null) {
+    			List interceptors = actionConfig.getInterceptors();
+    			for (Iterator i = interceptors.iterator(); i.hasNext(); ) {
+    				InterceptorMapping interceptorMapping = (InterceptorMapping) i.next();
+    				if (ValidationInterceptor.class.isInstance(interceptorMapping.getInterceptor()))
{
+    					ValidationInterceptor validationInterceptor = (ValidationInterceptor) interceptorMapping.getInterceptor();
+    				
+    					Set excludeMethods = validationInterceptor.getExcludeMethodsSet();
+    					Set includeMethods = validationInterceptor.getIncludeMethodsSet();
+    			
+    					if (MethodFilterInterceptorUtil.applyMethod(excludeMethods, includeMethods, actionMethod))
{
+    						addParameter("performValidation", Boolean.TRUE);
+    					}
+    					return;
+    				}
+    			}
+    		}
+    	}
     }
 
     /**
@@ -317,7 +359,7 @@
             if (validator instanceof FieldValidator) {
                 FieldValidator fieldValidator = (FieldValidator) validator;
                 if (fieldValidator.getFieldName().equals(name)) {
-                    validators.add(fieldValidator);
+                	validators.add(fieldValidator);
                 }
             }
         }

Modified: struts/action2/trunk/core/src/main/java/org/apache/struts/action2/components/UIBean.java
URL: http://svn.apache.org/viewcvs/struts/action2/trunk/core/src/main/java/org/apache/struts/action2/components/UIBean.java?rev=406273&r1=406272&r2=406273&view=diff
==============================================================================
--- struts/action2/trunk/core/src/main/java/org/apache/struts/action2/components/UIBean.java
(original)
+++ struts/action2/trunk/core/src/main/java/org/apache/struts/action2/components/UIBean.java
Sat May 13 23:25:18 2006
@@ -32,6 +32,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.Writer;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -848,6 +849,7 @@
             addParameter("form", form.getParameters());
 
             if ( name != null ) {
+            	// list should have been created by the form component
                 List tags = (List) form.getParameters().get("tagNames");
                 tags.add(name);
             }

Modified: struts/action2/trunk/core/src/main/resources/template/xhtml/form-close-validate.ftl
URL: http://svn.apache.org/viewcvs/struts/action2/trunk/core/src/main/resources/template/xhtml/form-close-validate.ftl?rev=406273&r1=406272&r2=406273&view=diff
==============================================================================
--- struts/action2/trunk/core/src/main/resources/template/xhtml/form-close-validate.ftl (original)
+++ struts/action2/trunk/core/src/main/resources/template/xhtml/form-close-validate.ftl Sat
May 13 23:25:18 2006
@@ -11,7 +11,7 @@
 * double validator
 END SNIPPET: supported-validators
 -->
-<#if parameters.validate?default(false) == true>
+<#if ((parameters.validate?default(false) == true) && (parameters.performValidation?default(false)
== true))>
 <script>
     function validateForm_${parameters.id}() {
         form = document.getElementById("${parameters.id}");

Modified: struts/action2/trunk/core/src/test/java/org/apache/struts/action2/views/jsp/ui/FormTagTest.java
URL: http://svn.apache.org/viewcvs/struts/action2/trunk/core/src/test/java/org/apache/struts/action2/views/jsp/ui/FormTagTest.java?rev=406273&r1=406272&r2=406273&view=diff
==============================================================================
--- struts/action2/trunk/core/src/test/java/org/apache/struts/action2/views/jsp/ui/FormTagTest.java
(original)
+++ struts/action2/trunk/core/src/test/java/org/apache/struts/action2/views/jsp/ui/FormTagTest.java
Sat May 13 23:25:18 2006
@@ -17,16 +17,28 @@
  */
 package org.apache.struts.action2.views.jsp.ui;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.struts.action2.TestAction;
 import org.apache.struts.action2.TestConfigurationProvider;
 import org.apache.struts.action2.StrutsConstants;
 import org.apache.struts.action2.config.Configuration;
+import org.apache.struts.action2.dispatcher.mapper.ActionMapper;
+import org.apache.struts.action2.dispatcher.mapper.ActionMapperFactory;
+import org.apache.struts.action2.dispatcher.mapper.DefaultActionMapper;
 import org.apache.struts.action2.views.jsp.AbstractUITagTest;
 import org.apache.struts.action2.views.jsp.ActionTag;
 
 import com.opensymphony.xwork.ActionContext;
+import com.opensymphony.xwork.ActionSupport;
 import com.opensymphony.xwork.ObjectFactory;
 import com.opensymphony.xwork.config.ConfigurationManager;
+import com.opensymphony.xwork.config.RuntimeConfiguration;
+import com.opensymphony.xwork.config.entities.ActionConfig;
+import com.opensymphony.xwork.config.entities.InterceptorMapping;
+import com.opensymphony.xwork.validator.ValidationInterceptor;
 
 
 /**
@@ -100,9 +112,56 @@
     }
     
     /**
-     * This test with form tag validation enabled
+     * This test with form tag validation enabled. Js validation script will appear
+     * cause action submited by the form is intercepted by validation interceptor which
+     * "include" all methods.
      */
-    public void testFormWithCustomOnsubmitEnabledWithValidateEnabled() throws Exception {
+    public void testFormWithCustomOnsubmitEnabledWithValidateEnabled1() throws Exception
{
+    	
+    	com.opensymphony.xwork.config.Configuration originalConfiguration = ConfigurationManager.getConfiguration();
+    	ObjectFactory originalObjectFactory = ObjectFactory.getObjectFactory();
+    	
+    	try {
+    	// used to determined if the form action needs js validation
+    	ConfigurationManager.setConfiguration(new com.opensymphony.xwork.config.impl.DefaultConfiguration()
{
+    		public RuntimeConfiguration getRuntimeConfiguration() {
+    			return new RuntimeConfiguration() {
+    				public ActionConfig getActionConfig(String namespace, String name) {
+    					ActionConfig actionConfig = new ActionConfig() {
+    						public List getInterceptors() {
+    							List interceptors = new ArrayList();
+    							
+    							ValidationInterceptor validationInterceptor = new ValidationInterceptor();
+    							validationInterceptor.setIncludeMethods("*");
+    							
+    							InterceptorMapping interceptorMapping = new InterceptorMapping();
+    							interceptorMapping.setName("validation");
+    							interceptorMapping.setInterceptor(validationInterceptor);
+    							interceptors.add(interceptorMapping);
+    							
+    							return interceptors;
+    						}
+    					};
+    					return actionConfig;
+    				}
+    				public Map getActionConfigs() {
+    					return null;
+    				}
+    			};
+    		}
+    	});
+    	
+    	// used by form tag to get "actionClass" parameter
+    	ObjectFactory.setObjectFactory(new ObjectFactory() {
+    		public Class getClassInstance(String className) throws ClassNotFoundException {
+    			if (DefaultActionMapper.class.getName().equals(className)) {
+    				return DefaultActionMapper.class;
+    			}
+    			return ActionSupport.class;
+    		}
+    	});
+    	
+    	
     	
     	FormTag tag = new FormTag();
     	tag.setPageContext(pageContext);
@@ -114,6 +173,7 @@
         tag.setTitle("mytitle");
         tag.setOnsubmit("submitMe()");
         tag.setValidate("true");
+        tag.setNamespace("");
         
         UpDownSelectTag t = new UpDownSelectTag();
         t.setPageContext(pageContext);
@@ -126,8 +186,95 @@
         tag.doEndTag();
     	
         verify(FormTag.class.getResource("Formtag-2.txt"));
+    	}
+    	finally {
+    		ConfigurationManager.setConfiguration(originalConfiguration);
+    		ObjectFactory.setObjectFactory(originalObjectFactory);
+    	}
     }
     
+    
+    /**
+     * This test with form tag validation enabled. Js validation script will not appear
+     * cause action submited by the form is intercepted by validation interceptor which
+     * "excludes" all methods.
+     */
+    public void testFormWithCustomOnsubmitEnabledWithValidateEnabled2() throws Exception
{
+    	
+    	com.opensymphony.xwork.config.Configuration originalConfiguration = ConfigurationManager.getConfiguration();
+    	ObjectFactory originalObjectFactory = ObjectFactory.getObjectFactory();
+    	
+    	try {
+    	// used to determined if the form action needs js validation
+    	ConfigurationManager.setConfiguration(new com.opensymphony.xwork.config.impl.DefaultConfiguration()
{
+    		public RuntimeConfiguration getRuntimeConfiguration() {
+    			return new RuntimeConfiguration() {
+    				public ActionConfig getActionConfig(String namespace, String name) {
+    					ActionConfig actionConfig = new ActionConfig() {
+    						public List getInterceptors() {
+    							List interceptors = new ArrayList();
+    							
+    							ValidationInterceptor validationInterceptor = new ValidationInterceptor();
+    							validationInterceptor.setExcludeMethods("*");
+    							
+    							InterceptorMapping interceptorMapping = new InterceptorMapping();
+    							interceptorMapping.setName("validation");
+    							interceptorMapping.setInterceptor(validationInterceptor);
+    							interceptors.add(interceptorMapping);
+    							
+    							return interceptors;
+    						}
+    					};
+    					return actionConfig;
+    				}
+    				public Map getActionConfigs() {
+    					return null;
+    				}
+    			};
+    		}
+    	});
+    	
+    	// used by form tag to get "actionClass" parameter
+    	ObjectFactory.setObjectFactory(new ObjectFactory() {
+    		public Class getClassInstance(String className) throws ClassNotFoundException {
+    			if (DefaultActionMapper.class.getName().equals(className)) {
+    				return DefaultActionMapper.class;
+    			}
+    			return ActionSupport.class;
+    		}
+    	});
+    	
+    	
+    	
+    	FormTag tag = new FormTag();
+    	tag.setPageContext(pageContext);
+    	tag.setName("myForm");
+    	tag.setMethod("POST");
+        tag.setAction("myAction");
+        tag.setAcceptcharset("UTF-8");
+        tag.setEnctype("myEncType");
+        tag.setTitle("mytitle");
+        tag.setOnsubmit("submitMe()");
+        tag.setValidate("true");
+        tag.setNamespace("");
+        
+        UpDownSelectTag t = new UpDownSelectTag();
+        t.setPageContext(pageContext);
+        t.setName("myUpDownSelectTag");
+        t.setList("{}");
+        
+        tag.doStartTag();
+        t.doStartTag();
+        t.doEndTag();
+        tag.doEndTag();
+    	
+        verify(FormTag.class.getResource("Formtag-11.txt"));
+    	}
+    	finally {
+    		ConfigurationManager.setConfiguration(originalConfiguration);
+    		ObjectFactory.setObjectFactory(originalObjectFactory);
+    	}
+    }
 
     /**
      * This test with form tag validation disabled.

Added: struts/action2/trunk/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/Formtag-11.txt
URL: http://svn.apache.org/viewcvs/struts/action2/trunk/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/Formtag-11.txt?rev=406273&view=auto
==============================================================================
--- struts/action2/trunk/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/Formtag-11.txt
(added)
+++ struts/action2/trunk/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/Formtag-11.txt
Sat May 13 23:25:18 2006
@@ -0,0 +1,34 @@
+<script src="/struts/xhtml/validation.js"></script>
+<form namespace="" id="myAction" name="myForm" onsubmit="submitMe(); return validateForm_myAction();"
action="/myAction.action" method="POST" enctype="myEncType" title="mytitle" accept-charset="UTF-8">
+<table class="wwFormTable"> <tr>
+    <td class="tdLabel"></td>
+    <td>	<script language="javascript" src="/struts/optiontransferselect.js"></script>
+<table>
+<tr><td>
+<select name="myUpDownSelectTag" size="5" id="myAction_myUpDownSelectTag" multiple="multiple">
+</select></td></tr>
+<tr><td>
+		&nbsp;<input type="button" value="^" onclick="moveOptionUp(document.getElementById('myAction_myUpDownSelectTag'),
'key', '');" />&nbsp;
+		&nbsp;<input type="button" value="v" onclick="moveOptionDown(document.getElementById('myAction_myUpDownSelectTag'),
'key', '');" />&nbsp;
+		&nbsp;<input type="button" value="*" onclick="selectAllOptions(document.getElementById('myAction_myUpDownSelectTag'),
'key', '');" />&nbsp;
+</td></tr>
+</table>
+</td>
+</tr>
+</table>
+</form>
+
+
+<script>
+	dojo.require("dojo.event.connect");
+	var containingForm = document.getElementById("myAction");
+	dojo.event.connect(containingForm, "onsubmit", 
+			function(evt) {
+				var updownselectObj = document.getElementById("myAction_myUpDownSelectTag");
+				selectAllOptionsExceptSome(updownselectObj, "key", "");
+			});
+</script>
+
+<!-- javascript that is needed for tooltips -->
+<script language="JavaScript" type="text/javascript">dojo.require("dojo.widget.html.Tooltip");dojo.require("dojo.fx.html");</script>
+

Propchange: struts/action2/trunk/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/Formtag-11.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: struts/action2/trunk/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/Formtag-2.txt
URL: http://svn.apache.org/viewcvs/struts/action2/trunk/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/Formtag-2.txt?rev=406273&r1=406272&r2=406273&view=diff
==============================================================================
--- struts/action2/trunk/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/Formtag-2.txt
(original)
+++ struts/action2/trunk/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/Formtag-2.txt
Sat May 13 23:25:18 2006
@@ -1,5 +1,5 @@
 <script src="/struts/xhtml/validation.js"></script>
-<form namespace="" id="myAction" name="myForm" onsubmit="submitMe(); return validateForm_myAction();"
action="myAction" method="POST" enctype="myEncType" title="mytitle" accept-charset="UTF-8">
+<form namespace="" id="myAction" name="myForm" onsubmit="submitMe(); return validateForm_myAction();"
action="/myAction.action" method="POST" enctype="myEncType" title="mytitle" accept-charset="UTF-8">
 <table class="wwFormTable"> <tr>
     <td class="tdLabel"></td>
     <td>	<script language="javascript" src="/struts/optiontransferselect.js"></script>



Mime
View raw message