You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mr...@apache.org on 2007/01/31 09:25:27 UTC

svn commit: r501762 - in /struts/struts2/trunk/core/src: main/java/org/apache/struts2/components/ main/resources/template/simple/ test/java/org/apache/struts2/views/jsp/ui/ test/resources/org/apache/struts2/views/jsp/ui/

Author: mrdon
Date: Wed Jan 31 00:25:24 2007
New Revision: 501762

URL: http://svn.apache.org/viewvc?view=rev&rev=501762
Log:
Added rendering of submit button body within tag rather than before
WW-1677

Added:
    struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-7.txt
Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Submit.java
    struts/struts2/trunk/core/src/main/resources/template/simple/submit.ftl
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/SubmitTest.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Submit.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Submit.java?view=diff&rev=501762&r1=501761&r2=501762
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Submit.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Submit.java Wed Jan 31 00:25:24 2007
@@ -20,9 +20,13 @@
  */
 package org.apache.struts2.components;
 
+import java.io.Writer;
+
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.struts2.views.annotations.StrutsTag;
 import org.apache.struts2.views.annotations.StrutsTagAttribute;
 
@@ -133,6 +137,9 @@
  */
 @StrutsTag(name="submit", tldTagClass="org.apache.struts2.views.jsp.ui.SubmitTag", description="Render a submit button")
 public class Submit extends FormButton implements RemoteUICallBean{
+    
+    private static final Log LOG = LogFactory.getLog(Submit.class);
+    
     final public static String TEMPLATE = "submit";
 
     protected String href;
@@ -216,6 +223,25 @@
      */
     protected boolean supportsImageType() {
         return true;
+    }
+    
+    /**
+     * Overrides to be able to render body in a template rather than always before the template
+     */
+    public boolean end(Writer writer, String body) {
+        evaluateParams();
+        try {
+            addParameter("body", body);
+            
+            mergeTemplate(writer, buildTemplateName(template, getDefaultTemplate()));
+        } catch (Exception e) {
+            LOG.error("error when rendering", e);
+        }
+        finally {
+            popComponentStack();
+        }
+
+        return false;
     }
 
     @StrutsTagAttribute(description="Topic that will trigger the remote call")

Modified: struts/struts2/trunk/core/src/main/resources/template/simple/submit.ftl
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/template/simple/submit.ftl?view=diff&rev=501762&r1=501761&r2=501762
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/template/simple/submit.ftl (original)
+++ struts/struts2/trunk/core/src/main/resources/template/simple/submit.ftl Wed Jan 31 00:25:24 2007
@@ -17,9 +17,10 @@
 </#if>
 <#include "/${parameters.templateDir}/simple/scripting-events.ftl"/>
 <#include "/${parameters.templateDir}/simple/common-attributes.ftl" />
-><#if parameters.label?exists><@s.property value="parameters.label"/><#rt/></#if></button>
+><#if parameters.body?length gt 0><@s.property value="parameters.body"/><#elseif parameters.label?exists><@s.property value="parameters.label"/><#rt/></#if></button>
 <#else>
 <#if parameters.type?exists && parameters.type=="image">
+<@s.property value="parameters.body"/>
 <input type="image"<#rt/>
 <#if parameters.label?exists>
  alt="${parameters.label?html}"<#rt/>
@@ -51,4 +52,4 @@
 <#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
 <#include "/${parameters.templateDir}/simple/common-attributes.ftl" />
 />
-</#if>
+</#if>
\ No newline at end of file

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/SubmitTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/SubmitTest.java?view=diff&rev=501762&r1=501761&r2=501762
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/SubmitTest.java (original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/SubmitTest.java Wed Jan 31 00:25:24 2007
@@ -23,9 +23,13 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.servlet.jsp.tagext.BodyContent;
+
 import org.apache.struts2.TestAction;
 import org.apache.struts2.views.jsp.AbstractUITagTest;
 
+import com.mockobjects.servlet.MockBodyContent;
+
 
 /**
  * Unit test for {@link SubmitTag}.
@@ -80,6 +84,25 @@
         tag.doEndTag();
 
         verify(TextFieldTag.class.getResource("Submit-3.txt"));
+    }
+    
+    public void testButtonSimpleWithBody() throws Exception {
+        TestAction testAction = (TestAction) action;
+        testAction.setFoo("bar");
+
+        SubmitTag tag = new SubmitTag();
+        tag.setPageContext(pageContext);
+        tag.setType("button");
+        tag.setName("myname");
+        tag.setValue("%{foo}");
+
+        tag.doStartTag();
+        StrutsBodyContent body = new StrutsBodyContent(null);
+        body.append("foo");
+        tag.setBodyContent(body);
+        tag.doEndTag();
+
+        verify(TextFieldTag.class.getResource("Submit-7.txt"));
     }
 
     public void testButtonWithLabel() throws Exception {

Added: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-7.txt
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-7.txt?view=auto&rev=501762
==============================================================================
--- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-7.txt (added)
+++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-7.txt Wed Jan 31 00:25:24 2007
@@ -0,0 +1,3 @@
+<tr>
+    <td colspan="2"><div align="right"><button type="submit" id="myname" name="myname" value="bar">foo</button></div></td>
+</tr>