Author: musachy
Date: Mon Nov  2 20:24:12 2009
New Revision: 832087

URL: http://svn.apache.org/viewvc?rev=832087&view=rev
Log:
WW-3312 Add "includeContext" to Form tag, like the Url tag does (default to 
true)

Added:
    
struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-13.txt
    
struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-14.txt
Modified:
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Form.java
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/FormTag.java
    struts/struts2/trunk/core/src/site/resources/tags/form.html
    
struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/FormTagTest.java

Modified: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Form.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Form.java?rev=832087&r1=832086&r2=832087&view=diff
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Form.java 
(original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Form.java 
Mon Nov  2 20:24:12 2009
@@ -104,8 +104,9 @@
     protected String portletMode;
     protected String windowState;
     protected String acceptcharset;
-    protected String focusElement;
+    protected boolean includeContext = true;
 
+    protected String focusElement;
     protected Configuration configuration;
     protected ObjectFactory objectFactory;
     protected UrlRenderer urlRenderer;
@@ -346,4 +347,9 @@
     public void setFocusElement(String focusElement) {
         this.focusElement = focusElement;
     }
+
+    @StrutsTagAttribute(description="Whether actual context should be included 
in URL", type="Boolean", defaultValue="true")
+    public void setIncludeContext(boolean includeContext) {
+        this.includeContext = includeContext;
+    }
 }

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?rev=832087&r1=832086&r2=832087&view=diff
==============================================================================
--- 
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
 Mon Nov  2 20:24:12 2009
@@ -151,7 +151,7 @@
 
                        ActionMapping mapping = new ActionMapping(actionName, 
namespace, actionMethod, formComponent.parameters);
                        String result = 
UrlHelper.buildUrl(formComponent.actionMapper.getUriFromActionMapping(mapping),
-                                       formComponent.request, 
formComponent.response, null);
+                                       formComponent.request, 
formComponent.response, null, null, formComponent.includeContext, true);
                        formComponent.addParameter("action", result);
 
                        // let's try to get the actual action class and name
@@ -186,7 +186,7 @@
               LOG.warn("No configuration found for the specified action: '" + 
actionName + "' in namespace: '" + namespace + "'. Form action defaulting to 
'action' attribute's literal value.");
             }
 
-                       String result = UrlHelper.buildUrl(action, 
formComponent.request, formComponent.response, null);
+                       String result = UrlHelper.buildUrl(action, 
formComponent.request, formComponent.response, null, null, 
formComponent.includeContext, true);
                        formComponent.addParameter("action", result);
 
                        // namespace: cut out anything between the start and 
the last /

Modified: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/FormTag.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/FormTag.java?rev=832087&r1=832086&r2=832087&view=diff
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/FormTag.java
 (original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/FormTag.java
 Mon Nov  2 20:24:12 2009
@@ -49,6 +49,7 @@
     protected String windowState;
     protected String acceptcharset;
     protected String focusElement;
+    protected boolean includeContext = true;
     
     public Component getBean(ValueStack stack, HttpServletRequest req, 
HttpServletResponse res) {
         return new Form(stack, req, res);
@@ -68,6 +69,7 @@
         form.setWindowState(windowState);
         form.setAcceptcharset(acceptcharset);
         form.setFocusElement(focusElement);
+        form.setIncludeContext(includeContext);
     }
 
 
@@ -118,4 +120,8 @@
     public void setFocusElement(String focusElement) {
         this.focusElement = focusElement;
     }
+
+    public void setIncludeContext(boolean includeContext) {
+        this.includeContext = includeContext;
+    }
 }

Modified: struts/struts2/trunk/core/src/site/resources/tags/form.html
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/site/resources/tags/form.html?rev=832087&r1=832086&r2=832087&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/site/resources/tags/form.html (original)
+++ struts/struts2/trunk/core/src/site/resources/tags/form.html Mon Nov  2 
20:24:12 2009
@@ -122,6 +122,14 @@
                                        <td align="left" valign="top">HTML id 
attribute</td>
                                </tr>
                                <tr>
+                                       <td align="left" 
valign="top">includeContext</td>
+                                       <td align="left" valign="top">false</td>
+                                       <td align="left" valign="top">true</td>
+                                       <td align="left" valign="top">false</td>
+                                       <td align="left" 
valign="top">Boolean</td>
+                                       <td align="left" valign="top">Whether 
actual context should be included in URL</td>
+                               </tr>
+                               <tr>
                                        <td align="left" 
valign="top">javascriptTooltip</td>
                                        <td align="left" valign="top">false</td>
                                        <td align="left" valign="top">false</td>

Modified: 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/FormTagTest.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/FormTagTest.java?rev=832087&r1=832086&r2=832087&view=diff
==============================================================================
--- 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/FormTagTest.java
 (original)
+++ 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/FormTagTest.java
 Mon Nov  2 20:24:12 2009
@@ -65,6 +65,35 @@
 
         verify(FormTag.class.getResource("Formtag-9.txt"));
     }
+
+    public void testFormWithoutContext() throws Exception {
+        request.setupGetContext("somecontext");
+
+        FormTag tag = new FormTag();
+        tag.setTheme("xhtml");
+        tag.setPageContext(pageContext);
+        tag.setAction("testAction");
+        tag.setIncludeContext(false);
+        tag.doStartTag();
+        tag.doEndTag();
+
+
+        verify(FormTag.class.getResource("Formtag-14.txt"));
+    }
+
+    public void testFormWithContext() throws Exception {
+        request.setupGetContext("/somecontext");
+
+        FormTag tag = new FormTag();
+        tag.setTheme("xhtml");
+        tag.setPageContext(pageContext);
+        tag.setAction("testAction");
+        tag.doStartTag();
+        tag.doEndTag();
+
+
+        verify(FormTag.class.getResource("Formtag-13.txt"));
+    }
     
     public void testFormWithActionAttributeContainingBothActionAndDMIMethod() 
throws Exception {
         FormTag tag = new FormTag();

Added: 
struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-13.txt
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-13.txt?rev=832087&view=auto
==============================================================================
--- 
struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-13.txt
 (added)
+++ 
struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-13.txt
 Mon Nov  2 20:24:12 2009
@@ -0,0 +1,4 @@
+<form id="testAction" name="testAction" 
action="/somecontext/testAction.action" method="post">
+<table class="wwFormTable">
+</table>
+</form>
\ No newline at end of file

Added: 
struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-14.txt
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-14.txt?rev=832087&view=auto
==============================================================================
--- 
struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-14.txt
 (added)
+++ 
struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-14.txt
 Mon Nov  2 20:24:12 2009
@@ -0,0 +1,4 @@
+<form id="testAction" name="testAction" action="/testAction.action" 
method="post">
+<table class="wwFormTable">
+</table>
+</form>
\ No newline at end of file


Reply via email to