1. opensymphony
  2. webwork

Commits

jcarreira  committed a369c73

WW-586: form tag now searches for default namespace from current action invocation
WW-522: made the action attribute optional

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@468573baa09-0c28-0410-bef9-dab3c582ae83

  • Participants
  • Parent commits cc7a31b
  • Branches master

Comments (0)

Files changed (7)

File src/etc/taglib.tld

View file
         </attribute>
         <attribute>
             <name>action</name>
-            <required>true</required>
+            <required>false</required>
             <rtexprvalue>true</rtexprvalue>
         </attribute>
         <attribute>

File src/java/com/opensymphony/webwork/views/jsp/ActionTag.java

View file
 import com.opensymphony.webwork.dispatcher.SessionMap;
 
 import com.opensymphony.xwork.ActionContext;
-import com.opensymphony.xwork.ActionInvocation;
 import com.opensymphony.xwork.ActionProxy;
 import com.opensymphony.xwork.ActionProxyFactory;
 import com.opensymphony.xwork.util.OgnlValueStack;
         return EVAL_BODY_INCLUDE;
     }
 
-    String buildNamespace() {
-        ActionContext context = new ActionContext(getStack().getContext());
-        ActionInvocation invocation = context.getActionInvocation();
-
-        if (invocation == null) {
-            // Path is always original path, even if it is included in page with another path
-            HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
-            String actionPath = request.getServletPath();
-
-            return ServletDispatcher.getNamespaceFromServletPath(actionPath);
-        } else {
-            return invocation.getProxy().getNamespace();
-        }
-    }
-
     private Map createExtraContext() {
         Map parentParams = null;
 
      * attempt to derive a namespace using buildNamespace().  The ActionProxy
      * and the namespace will be saved into the instance variables proxy and
      * namespace respectively.
-     * @see #buildNamespace
+     * @see com.opensymphony.webwork.views.jsp.TagUtils#buildNamespace
      */
     private void executeAction() throws JspException {
         String actualName = findString(name);
         String namespace;
 
         if (namespaceAttr == null) {
-            namespace = buildNamespace();
+            namespace = TagUtils.buildNamespace(getStack(), (HttpServletRequest) pageContext.getRequest());
         } else {
             namespace = findString(namespaceAttr);
         }

File src/java/com/opensymphony/webwork/views/jsp/TagUtils.java

View file
 import com.opensymphony.webwork.util.AttributeMap;
 
 import com.opensymphony.xwork.ActionContext;
+import com.opensymphony.xwork.ActionInvocation;
 import com.opensymphony.xwork.util.OgnlValueStack;
 
 import java.util.Map;
 
         return stack;
     }
+
+    public static String buildNamespace(OgnlValueStack stack, HttpServletRequest request) {
+        ActionContext context = new ActionContext(stack.getContext());
+        ActionInvocation invocation = context.getActionInvocation();
+
+        if (invocation == null) {
+            // Path is always original path, even if it is included in page with another path
+            String actionPath = request.getServletPath();
+
+            return ServletDispatcher.getNamespaceFromServletPath(actionPath);
+        } else {
+            return invocation.getProxy().getNamespace();
+        }
+    }
 }

File src/java/com/opensymphony/webwork/views/jsp/ui/FormTag.java

View file
 import com.opensymphony.webwork.ServletActionContext;
 import com.opensymphony.webwork.config.Configuration;
 import com.opensymphony.webwork.validators.ScriptValidationAware;
+import com.opensymphony.webwork.views.jsp.TagUtils;
 import com.opensymphony.webwork.views.util.UrlHelper;
-
 import com.opensymphony.xwork.ObjectFactory;
 import com.opensymphony.xwork.config.ConfigurationManager;
 import com.opensymphony.xwork.config.entities.ActionConfig;
 import com.opensymphony.xwork.util.OgnlValueStack;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.jsp.JspException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
 
 
 /**
             }
 
             String action = (String) findValue(actionAttr, String.class);
-            String namespace = (String) findValue(namespaceAttr, String.class);
+            String namespace;
+
+            if (namespaceAttr == null) {
+                namespace = TagUtils.buildNamespace(getStack(), (HttpServletRequest) pageContext.getRequest());
+            } else {
+                namespace = findString(namespaceAttr);
+            }
 
             if (namespace == null) {
                 namespace = "";

File src/test/com/opensymphony/webwork/views/jsp/ui/FormTagTest.java

View file
     //~ Methods ////////////////////////////////////////////////////////////////
 
     public void testClientSideValidation() throws Exception {
+        request.setupGetServletPath("/testAction");
+
         TestAction testAction = (TestAction) action;
         testAction.setFoo("bar");
 
     }
 
     public void testForm() throws Exception {
+        request.setupGetServletPath("/testAction");
+
         TestAction testAction = (TestAction) action;
         testAction.setFoo("bar");
 
         verify(FormTag.class.getResource("Formtag-1.txt"));
     }
 
+    public void testFormWithNamespaceDefaulting() throws Exception {
+        request.setupGetServletPath("/testNamespace/testNamespaceAction");
+
+        TestAction testAction = (TestAction) action;
+        testAction.setFoo("bar");
+
+        FormTag tag = new FormTag();
+        tag.setPageContext(pageContext);
+        tag.setName("'myForm'");
+        tag.setMethod("'POST'");
+        tag.setAction("'testNamespaceAction'");
+
+        tag.doStartTag();
+        tag.doEndTag();
+
+        verify(FormTag.class.getResource("Formtag-3.txt"));
+    }
+
+    public void testFormWithNoAction() throws Exception {
+        FormTag tag = new FormTag();
+        tag.setPageContext(pageContext);
+        tag.doStartTag();
+        tag.doEndTag();
+
+        verify(FormTag.class.getResource("Formtag-4.txt"));
+    }
+
     protected void setUp() throws Exception {
         super.setUp();
         ConfigurationManager.clearConfigurationProviders();

File src/test/com/opensymphony/webwork/views/jsp/ui/Formtag-3.txt

View file
+<table>
+<form name="myForm" action="/testNamespace/testNamespaceAction.action" method="POST" >
+</form>
+</table>

File src/test/com/opensymphony/webwork/views/jsp/ui/Formtag-4.txt

View file
+<table>
+<form >
+</form>
+</table>