Author: jholmes
Date: Tue Jul 31 18:14:18 2007
New Revision: 561619

URL: http://svn.apache.org/viewvc?view=rev&rev=561619
Log:
Log a warning if user specifies a namespace and action with the <s:form> tag 
and the action is not found in the namespace. Right now this fails silently and 
the user gets an HTTP 404 typically. I've had this happen to me and it took a 
little while to realize I had the wrong namespace or action name. This warning 
should help users figure out the issue faster by giving them a heads up.

Modified:
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java

Modified: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java?view=diff&rev=561619&r1=561618&r2=561619
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java
 (original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java
 Tue Jul 31 18:14:18 2007
@@ -23,6 +23,8 @@
 import java.io.IOException;
 import java.io.Writer;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.struts2.StrutsException;
 import org.apache.struts2.dispatcher.mapper.ActionMapping;
 import org.apache.struts2.views.util.UrlHelper;
@@ -36,6 +38,11 @@
  * 
  */
 public class ServletUrlRenderer implements UrlRenderer {
+    /**
+     * Provide a logging instance.
+     */
+    private static final Log LOG = LogFactory.getLog(ServletUrlRenderer.class);
+
 
        /**
         * [EMAIL PROTECTED]
@@ -152,10 +159,14 @@
                        }
                } else if (action != null) {
                        // Since we can't find an action alias in the 
configuration, we just
-                       // assume
-                       // the action attribute supplied is the path to be used 
as the uri
-                       // this
-                       // form is submitting to.
+                       // assume the action attribute supplied is the path to 
be used as
+                       // the URI this form is submitting to.
+
+      // Warn user that the specified namespace/action combo
+      // was not found in the configuration.
+      if (namespace != null) {
+          LOG.warn("No configuration found for the specified action: '" + 
action + "' in namespace: '" + namespace + "'. Form action defaulting to 
'action' attribute's literal value.");
+      }
 
                        String result = UrlHelper.buildUrl(action, 
formComponent.request, formComponent.response, null);
                        formComponent.addParameter("action", result);
@@ -185,9 +196,7 @@
 
                // WW-1284
                // evaluate if client-side js is to be enabled. (if validation
-               // interceptor
-               // does allow validation eg. method is not filtered out)
+               // interceptor does allow validation eg. method is not filtered 
out)
                formComponent.evaluateClientSideJsEnablement(actionName, 
namespace, actionMethod);
        }
-
 }


Reply via email to