Author: musachy Date: Fri Jul 18 17:08:47 2008 New Revision: 678079 URL: http://svn.apache.org/viewvc?rev=678079&view=rev Log: WW-1677 <s:submit type="button" does not render the enclosed content inside properly
Thanks to Eric Martin and Mike Bydalek for the patch. Added: struts/struts2/trunk/core/src/main/resources/template/css_xhtml/submit-close.ftl struts/struts2/trunk/core/src/main/resources/template/simple/submit-close.ftl struts/struts2/trunk/core/src/main/resources/template/xhtml/submit-close.ftl struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-10.txt struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-8.txt struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-9.txt Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/FormButton.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Reset.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Submit.java struts/struts2/trunk/core/src/main/resources/template/css_xhtml/submit.ftl struts/struts2/trunk/core/src/main/resources/template/simple/submit.ftl struts/struts2/trunk/core/src/main/resources/template/xhtml/submit.ftl struts/struts2/trunk/core/src/site/resources/tags/reset.html struts/struts2/trunk/core/src/site/resources/tags/submit.html struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/SubmitTest.java 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/FormButton.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/FormButton.java?rev=678079&r1=678078&r2=678079&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/FormButton.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/FormButton.java Fri Jul 18 17:08:47 2008 @@ -34,7 +34,7 @@ /** * FormButton. */ -public abstract class FormButton extends UIBean { +public abstract class FormButton extends ClosingUIBean { static final String BUTTONTYPE_INPUT = "input"; static final String BUTTONTYPE_BUTTON = "button"; Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Reset.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Reset.java?rev=678079&r1=678078&r2=678079&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Reset.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Reset.java Fri Jul 18 17:08:47 2008 @@ -74,6 +74,9 @@ super(stack, request, response); } + public String getDefaultOpenTemplate() { + return "empty"; + } protected String getDefaultTemplate() { return Reset.TEMPLATE; } 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?rev=678079&r1=678078&r2=678079&view=diff ============================================================================== --- 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 Fri Jul 18 17:08:47 2008 @@ -52,15 +52,20 @@ description="Render a submit button", allowDynamicAttributes=true) public class Submit extends FormButton { - + private static final Logger LOG = LoggerFactory.getLogger(Submit.class); - final public static String TEMPLATE = "submit"; + final public static String OPEN_TEMPLATE = "submit"; + final public static String TEMPLATE = "submit-close"; protected String src; public Submit(ValueStack stack, HttpServletRequest request, HttpServletResponse response) { super(stack, request, response); } + public String getDefaultOpenTemplate() { + return OPEN_TEMPLATE; + } + protected String getDefaultTemplate() { return TEMPLATE; } @@ -76,10 +81,10 @@ super.evaluateParams(); } - + public void evaluateExtraParams() { super.evaluateExtraParams(); - + if (src != null) addParameter("src", findString(src)); } @@ -92,12 +97,18 @@ protected boolean supportsImageType() { return true; } - + @StrutsTagAttribute(description="Supply an image src for <i>image</i> type submit button. Will have no effect for types <i>input</i> and <i>button</i>.") public void setSrc(String src) { this.src = src; } - + + + @Override + public boolean usesBody() { + return true; + } + /** * Overrides to be able to render body in a template rather than always before the template */ @@ -105,7 +116,7 @@ evaluateParams(); try { addParameter("body", body); - + mergeTemplate(writer, buildTemplateName(template, getDefaultTemplate())); } catch (Exception e) { LOG.error("error when rendering", e); Added: struts/struts2/trunk/core/src/main/resources/template/css_xhtml/submit-close.ftl URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/template/css_xhtml/submit-close.ftl?rev=678079&view=auto ============================================================================== --- struts/struts2/trunk/core/src/main/resources/template/css_xhtml/submit-close.ftl (added) +++ struts/struts2/trunk/core/src/main/resources/template/css_xhtml/submit-close.ftl Fri Jul 18 17:08:47 2008 @@ -0,0 +1,6 @@ +<#include "/${parameters.templateDir}/simple/submit-close.ftl" /> +<#if parameters.labelposition?default("top") == 'top'> +</div> <#t/> +<#else> +</span> <#t/> +</#if> Modified: struts/struts2/trunk/core/src/main/resources/template/css_xhtml/submit.ftl URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/template/css_xhtml/submit.ftl?rev=678079&r1=678078&r2=678079&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/resources/template/css_xhtml/submit.ftl (original) +++ struts/struts2/trunk/core/src/main/resources/template/css_xhtml/submit.ftl Fri Jul 18 17:08:47 2008 @@ -33,8 +33,3 @@ </#if> ><#t/> <#include "/${parameters.templateDir}/simple/submit.ftl" /> -<#if parameters.labelposition?default("top") == 'top'> -</div> <#t/> -<#else> -</span> <#t/> -</#if> Added: struts/struts2/trunk/core/src/main/resources/template/simple/submit-close.ftl URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/template/simple/submit-close.ftl?rev=678079&view=auto ============================================================================== --- struts/struts2/trunk/core/src/main/resources/template/simple/submit-close.ftl (added) +++ struts/struts2/trunk/core/src/main/resources/template/simple/submit-close.ftl Fri Jul 18 17:08:47 2008 @@ -0,0 +1,4 @@ +<#if parameters.type?exists && parameters.type=="button"> +<#if (parameters.body)?default("")?length gt 0><@s.property value="parameters.body"/><#elseif parameters.label?exists><@s.property value="parameters.label"/><#rt/></#if> +</button> +</#if> 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?rev=678079&r1=678078&r2=678079&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/resources/template/simple/submit.ftl (original) +++ struts/struts2/trunk/core/src/main/resources/template/simple/submit.ftl Fri Jul 18 17:08:47 2008 @@ -49,7 +49,7 @@ <#include "/${parameters.templateDir}/simple/scripting-events.ftl"/> <#include "/${parameters.templateDir}/simple/common-attributes.ftl" /> <#include "/${parameters.templateDir}/simple/dynamic-attributes.ftl" /> -><#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"/> Added: struts/struts2/trunk/core/src/main/resources/template/xhtml/submit-close.ftl URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/template/xhtml/submit-close.ftl?rev=678079&view=auto ============================================================================== --- struts/struts2/trunk/core/src/main/resources/template/xhtml/submit-close.ftl (added) +++ struts/struts2/trunk/core/src/main/resources/template/xhtml/submit-close.ftl Fri Jul 18 17:08:47 2008 @@ -0,0 +1,3 @@ +<#include "/${parameters.templateDir}/simple/submit-close.ftl" /> +</div><#t/> +<#include "/${parameters.templateDir}/xhtml/controlfooter.ftl" /> Modified: struts/struts2/trunk/core/src/main/resources/template/xhtml/submit.ftl URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/template/xhtml/submit.ftl?rev=678079&r1=678078&r2=678079&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/resources/template/xhtml/submit.ftl (original) +++ struts/struts2/trunk/core/src/main/resources/template/xhtml/submit.ftl Fri Jul 18 17:08:47 2008 @@ -27,5 +27,3 @@ </#if> ><#t/> <#include "/${parameters.templateDir}/simple/submit.ftl" /> -</div><#t/> -<#include "/${parameters.templateDir}/xhtml/controlfooter.ftl" /> Modified: struts/struts2/trunk/core/src/site/resources/tags/reset.html URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/site/resources/tags/reset.html?rev=678079&r1=678078&r2=678079&view=diff ============================================================================== --- struts/struts2/trunk/core/src/site/resources/tags/reset.html (original) +++ struts/struts2/trunk/core/src/site/resources/tags/reset.html Fri Jul 18 17:08:47 2008 @@ -268,6 +268,14 @@ <td align="left" valign="top">Set the html onselect attribute on rendered html element</td> </tr> <tr> + <td align="left" valign="top">openTemplate</td> + <td align="left" valign="top">false</td> + <td align="left" valign="top"></td> + <td align="left" valign="top">false</td> + <td align="left" valign="top">String</td> + <td align="left" valign="top">Set template to use for opening the rendered html.</td> + </tr> + <tr> <td align="left" valign="top">required</td> <td align="left" valign="top">false</td> <td align="left" valign="top">false</td> Modified: struts/struts2/trunk/core/src/site/resources/tags/submit.html URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/site/resources/tags/submit.html?rev=678079&r1=678078&r2=678079&view=diff ============================================================================== --- struts/struts2/trunk/core/src/site/resources/tags/submit.html (original) +++ struts/struts2/trunk/core/src/site/resources/tags/submit.html Fri Jul 18 17:08:47 2008 @@ -268,6 +268,14 @@ <td align="left" valign="top">Set the html onselect attribute on rendered html element</td> </tr> <tr> + <td align="left" valign="top">openTemplate</td> + <td align="left" valign="top">false</td> + <td align="left" valign="top"></td> + <td align="left" valign="top">false</td> + <td align="left" valign="top">String</td> + <td align="left" valign="top">Set template to use for opening the rendered html.</td> + </tr> + <tr> <td align="left" valign="top">required</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/SubmitTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/SubmitTest.java?rev=678079&r1=678078&r2=678079&view=diff ============================================================================== --- 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 Fri Jul 18 17:08:47 2008 @@ -34,60 +34,63 @@ */ public class SubmitTest extends AbstractUITagTest { - public void testDefaultValues() throws Exception { + public void testButtonSimpleWithBody() throws Exception { TestAction testAction = (TestAction) action; testAction.setFoo("bar"); SubmitTag tag = new SubmitTag(); + tag.setTheme("simple"); tag.setPageContext(pageContext); - tag.setLabel("mylabel"); + tag.setType("button"); tag.setName("myname"); - tag.setTitle("mytitle"); + tag.setLabel("yoyoyoyoy"); + tag.setValue("%{foo}"); + StrutsBodyContent body = new StrutsBodyContent(null); + body.print("foo"); + tag.setBodyContent(body); tag.doStartTag(); tag.doEndTag(); - verify(TextFieldTag.class.getResource("Submit-2.txt")); + verify(TextFieldTag.class.getResource("Submit-10.txt")); } - public void testSimple() throws Exception { + public void testDefaultValues() throws Exception { TestAction testAction = (TestAction) action; testAction.setFoo("bar"); SubmitTag tag = new SubmitTag(); tag.setPageContext(pageContext); tag.setLabel("mylabel"); - tag.setAlign("left"); tag.setName("myname"); - tag.setValue("%{foo}"); - tag.setDisabled("true"); - tag.setTabindex("1"); - + tag.setTitle("mytitle"); + tag.doStartTag(); tag.doEndTag(); - verify(TextFieldTag.class.getResource("Submit-1.txt")); + verify(TextFieldTag.class.getResource("Submit-2.txt")); } - public void testButtonSimple() throws Exception { + public void testSimple() throws Exception { TestAction testAction = (TestAction) action; testAction.setFoo("bar"); SubmitTag tag = new SubmitTag(); tag.setPageContext(pageContext); - tag.setType("button"); + tag.setLabel("mylabel"); + tag.setAlign("left"); tag.setName("myname"); tag.setValue("%{foo}"); tag.setDisabled("true"); tag.setTabindex("1"); - + tag.doStartTag(); tag.doEndTag(); - verify(TextFieldTag.class.getResource("Submit-3.txt")); + verify(TextFieldTag.class.getResource("Submit-1.txt")); } - public void testButtonSimpleWithBody() throws Exception { + public void testButtonSimple() throws Exception { TestAction testAction = (TestAction) action; testAction.setFoo("bar"); @@ -96,14 +99,13 @@ tag.setType("button"); tag.setName("myname"); tag.setValue("%{foo}"); + tag.setDisabled("true"); + tag.setTabindex("1"); tag.doStartTag(); - StrutsBodyContent body = new StrutsBodyContent(null); - body.append("foo"); - tag.setBodyContent(body); tag.doEndTag(); - verify(TextFieldTag.class.getResource("Submit-7.txt")); + verify(TextFieldTag.class.getResource("Submit-3.txt")); } public void testButtonWithLabel() throws Exception { @@ -176,7 +178,7 @@ tag.doStartTag(); tag.doEndTag(); - assertEquals("<button type=\"submit\" id=\"myname\" name=\"action:manager!update\" value=\"Submit\">mylabel</button>", writer.toString().trim()); + verify(TextFieldTag.class.getResource("Submit-7.txt")); } public void testSimpleThemeImageUsingActionOnly() throws Exception { @@ -196,7 +198,7 @@ tag.doStartTag(); tag.doEndTag(); - assertEquals("<button type=\"submit\" id=\"myname\" name=\"action:manager\" value=\"Submit\">mylabel</button>", writer.toString().trim()); + verify(TextFieldTag.class.getResource("Submit-8.txt")); } public void testSimpleThemeImageUsingMethodOnly() throws Exception { @@ -216,7 +218,7 @@ tag.doStartTag(); tag.doEndTag(); - assertEquals("<button type=\"submit\" id=\"myname\" name=\"method:update\" value=\"Submit\">mylabel</button>", writer.toString().trim()); + verify(TextFieldTag.class.getResource("Submit-9.txt")); } public void testSimpleThemeInput() throws Exception { Added: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-10.txt URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-10.txt?rev=678079&view=auto ============================================================================== --- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-10.txt (added) +++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-10.txt Fri Jul 18 17:08:47 2008 @@ -0,0 +1 @@ +<button type="submit" id="myname" name="myname" value="bar">foo</button> \ No newline at end of file Modified: 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?rev=678079&r1=678078&r2=678079&view=diff ============================================================================== --- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-7.txt (original) +++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-7.txt Fri Jul 18 17:08:47 2008 @@ -1,3 +1,2 @@ -<tr> - <td colspan="2"><div align="right"><button type="submit" id="myname" name="myname" value="bar">foo</button></div></td> -</tr> +<button type="submit" id="myname" name="action:manager!update" value="Submit">mylabel +</button> Added: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-8.txt URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-8.txt?rev=678079&view=auto ============================================================================== --- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-8.txt (added) +++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-8.txt Fri Jul 18 17:08:47 2008 @@ -0,0 +1,2 @@ +<button type="submit" id="myname" name="action:manager" value="Submit">mylabel +</button> \ No newline at end of file Added: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-9.txt URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-9.txt?rev=678079&view=auto ============================================================================== --- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-9.txt (added) +++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Submit-9.txt Fri Jul 18 17:08:47 2008 @@ -0,0 +1,2 @@ +<button type="submit" id="myname" name="method:update" value="Submit">mylabel +</button> \ No newline at end of file