Author: lukaszlenart Date: Thu Apr 1 21:04:39 2010 New Revision: 930097 URL: http://svn.apache.org/viewvc?rev=930097&view=rev Log: Resolved WW-2624 - added src attribute to reset tag to generate reset button as a image
Added: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-5.txt - copied, changed from r927528, struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-4.txt struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-6.txt - copied, changed from r927528, struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-4.txt struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-7.txt struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-8.txt struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-9.txt Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Reset.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/ResetTag.java struts/struts2/trunk/core/src/main/resources/template/simple/reset.ftl struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/ResetTest.java struts/struts2/trunk/core/src/test/resources/org/apache/struts2/TestAction.properties 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=930097&r1=930096&r2=930097&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 Thu Apr 1 21:04:39 2010 @@ -21,13 +21,12 @@ package org.apache.struts2.components; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import com.opensymphony.xwork2.util.ValueStack; import org.apache.struts2.views.annotations.StrutsTag; import org.apache.struts2.views.annotations.StrutsTagAttribute; -import com.opensymphony.xwork2.util.ValueStack; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; /** * <!-- START SNIPPET: javadoc --> @@ -65,10 +64,7 @@ import com.opensymphony.xwork2.util.Valu public class Reset extends FormButton { final public static String TEMPLATE = "reset"; - protected String action; - protected String method; - protected String align; - protected String type; + protected String src; public Reset(ValueStack stack, HttpServletRequest request, HttpServletResponse response) { super(stack, request, response); @@ -77,12 +73,18 @@ public class Reset extends FormButton { public String getDefaultOpenTemplate() { return "empty"; } + protected String getDefaultTemplate() { return Reset.TEMPLATE; } - public void evaluateParams() { + public void evaluateExtraParams() { + super.evaluateExtraParams(); + if (src != null) + addParameter("src", findString(src)); + } + public void evaluateParams() { if ((key == null) && (value == null)) { value = "Reset"; } @@ -90,9 +92,7 @@ public class Reset extends FormButton { if (((key != null)) && (value == null)) { this.value = "%{getText('"+key +"')}"; } - super.evaluateParams(); - } /** @@ -110,4 +110,9 @@ public class Reset extends FormButton { super.setLabel(label); } + @StrutsTagAttribute(description="Supply an image src for <i>image</i> type reset button. Will have no effect for types <i>input</i> and <i>button</i>.") + public void setSrc(String src) { + this.src = src; + } + } Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/ResetTag.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/ResetTag.java?rev=930097&r1=930096&r2=930097&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/ResetTag.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/ResetTag.java Thu Apr 1 21:04:39 2010 @@ -21,13 +21,12 @@ package org.apache.struts2.views.jsp.ui; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import com.opensymphony.xwork2.util.ValueStack; import org.apache.struts2.components.Component; import org.apache.struts2.components.Reset; -import com.opensymphony.xwork2.util.ValueStack; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; /** * @see org.apache.struts2.components.Reset @@ -40,6 +39,7 @@ public class ResetTag extends AbstractUI protected String method; protected String align; protected String type; + protected String src; public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) { return new Reset(stack, req, res); @@ -53,6 +53,7 @@ public class ResetTag extends AbstractUI reset.setMethod(method); reset.setAlign(align); reset.setType(type); + reset.setSrc(src); } public void setAction(String action) { @@ -71,4 +72,8 @@ public class ResetTag extends AbstractUI this.type = type; } + public void setSrc(String src) { + this.src = src; + } + } Modified: struts/struts2/trunk/core/src/main/resources/template/simple/reset.ftl URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/template/simple/reset.ftl?rev=930097&r1=930096&r2=930097&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/resources/template/simple/reset.ftl (original) +++ struts/struts2/trunk/core/src/main/resources/template/simple/reset.ftl Thu Apr 1 21:04:39 2010 @@ -40,7 +40,15 @@ <#include "/${parameters.templateDir}/simple/scripting-events.ftl"/> <#include "/${parameters.templateDir}/simple/common-attributes.ftl" /> <#include "/${parameters.templateDir}/simple/dynamic-attributes.ftl" /> -><#if parameters.label??><@s.property value="parameters.label"/><#rt/></#if></button> +><#if parameters.src??> +<img<#rt/> +<#if parameters.label??> + alt="${parameters.label?html}"<#rt/> +</#if> +<#if parameters.src??> + src="${parameters.src?html}"<#rt/> +</#if> +/><#else><#if parameters.label??><@s.property value="parameters.label"/><#rt/></#if></#if></button> <#else> <input type="reset"<#rt/> <#if parameters.name??> @@ -65,4 +73,4 @@ <#include "/${parameters.templateDir}/simple/common-attributes.ftl" /> <#include "/${parameters.templateDir}/simple/dynamic-attributes.ftl" /> /> -</#if> +</#if> \ No newline at end of file Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/ResetTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/ResetTest.java?rev=930097&r1=930096&r2=930097&view=diff ============================================================================== --- struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/ResetTest.java (original) +++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/ResetTest.java Thu Apr 1 21:04:39 2010 @@ -21,12 +21,12 @@ package org.apache.struts2.views.jsp.ui; -import java.util.HashMap; -import java.util.Map; - import org.apache.struts2.TestAction; import org.apache.struts2.views.jsp.AbstractUITagTest; +import java.util.HashMap; +import java.util.Map; + /** * Reset Component Test. * @@ -42,6 +42,7 @@ public class ResetTest extends AbstractU tag.setLabel("mylabel"); tag.setName("myname"); tag.setTitle("mytitle"); + tag.setSrc("/images/test.png"); tag.doStartTag(); tag.doEndTag(); @@ -100,6 +101,119 @@ public class ResetTest extends AbstractU verify(TextFieldTag.class.getResource("Reset-4.txt")); } + public void testImageSimple() throws Exception { + TestAction testAction = (TestAction) action; + testAction.setFoo("bar"); + + ResetTag tag = new ResetTag(); + tag.setPageContext(pageContext); + tag.setType("button"); + tag.setName("myname"); + tag.setValue("%{foo}"); + tag.setDisabled("true"); + + tag.doStartTag(); + tag.doEndTag(); + + verify(TextFieldTag.class.getResource("Reset-5.txt")); + } + + public void testImageWithSrc() throws Exception { + TestAction testAction = (TestAction) action; + testAction.setFoo("bar"); + + ResetTag tag = new ResetTag(); + tag.setPageContext(pageContext); + tag.setType("button"); + tag.setName("myname"); + tag.setLabel("mylabel"); + tag.setValue("%{foo}"); + tag.setSrc("some.gif"); + + tag.doStartTag(); + tag.doEndTag(); + + verify(TextFieldTag.class.getResource("Reset-6.txt")); + } + + public void testImageWithExpressionSrc() throws Exception { + TestAction testAction = (TestAction) action; + testAction.setFoo("bar"); + + ResetTag tag = new ResetTag(); + tag.setPageContext(pageContext); + tag.setType("button"); + tag.setName("myname"); + tag.setLabel("mylabel"); + tag.setValue("%{foo}"); + tag.setSrc("%{getText(\"some.image.from.properties\")}"); + + tag.doStartTag(); + tag.doEndTag(); + + verify(TextFieldTag.class.getResource("Reset-6.txt")); + } + + public void testSimpleThemeImageUsingActionAndMethod() throws Exception { + TestAction testAction = (TestAction) action; + testAction.setFoo("bar"); + + ResetTag tag = new ResetTag(); + tag.setPageContext(pageContext); + tag.setTheme("simple"); + tag.setType("button"); + tag.setName("myname"); + tag.setLabel("mylabel"); + tag.setAction("manager"); + tag.setMethod("update"); + tag.setAlign("left"); + + tag.doStartTag(); + tag.doEndTag(); + + verify(TextFieldTag.class.getResource("Reset-7.txt")); + } + + public void testSimpleThemeImageUsingActionOnly() throws Exception { + TestAction testAction = (TestAction) action; + testAction.setFoo("bar"); + + ResetTag tag = new ResetTag(); + tag.setPageContext(pageContext); + tag.setTheme("simple"); + tag.setType("button"); + tag.setName("myname"); + tag.setLabel("mylabel"); + tag.setAction("manager"); + tag.setMethod(null); // no method + tag.setAlign("left"); + + tag.doStartTag(); + tag.doEndTag(); + + verify(TextFieldTag.class.getResource("Reset-8.txt")); + } + + public void testSimpleThemeImageUsingMethodOnly() throws Exception { + TestAction testAction = (TestAction) action; + testAction.setFoo("bar"); + + ResetTag tag = new ResetTag(); + tag.setPageContext(pageContext); + tag.setTheme("simple"); + tag.setType("button"); + tag.setName("myname"); + tag.setLabel("mylabel"); + tag.setAction(null); // no action + tag.setMethod("update"); + tag.setAlign("left"); + + tag.doStartTag(); + tag.doEndTag(); + + verify(TextFieldTag.class.getResource("Reset-9.txt")); + } + /** * Initialize a map of {...@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag * property testing. Will be used when calling {...@link #verifyGenericProperties(AbstractUITag, Modified: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/TestAction.properties URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/TestAction.properties?rev=930097&r1=930096&r2=930097&view=diff ============================================================================== --- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/TestAction.properties (original) +++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/TestAction.properties Thu Apr 1 21:04:39 2010 @@ -22,4 +22,5 @@ simpleKey=Simple Message expressionKey=Foo is ${foo} messageFormatKey=Params are {0} {1} {2} foo.bar.baz=This should start with foo -bar.baz=No foo here \ No newline at end of file +bar.baz=No foo here +some.image.from.properties=some.gif \ No newline at end of file Copied: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-5.txt (from r927528, struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-4.txt) URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-5.txt?p2=struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-5.txt&p1=struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-4.txt&r1=927528&r2=930097&rev=930097&view=diff ============================================================================== --- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-4.txt (original) +++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-5.txt Thu Apr 1 21:04:39 2010 @@ -1,3 +1,3 @@ <tr> - <td colspan="2"><div align="left"><button type="reset" name="myname" value="bar">mylabel</button></div></td> -</tr> + <td colspan="2"><div align="right"><button type="reset" name="myname" value="bar" disabled="disabled">bar</button></div></td> +</tr> \ No newline at end of file Copied: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-6.txt (from r927528, struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-4.txt) URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-6.txt?p2=struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-6.txt&p1=struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-4.txt&r1=927528&r2=930097&rev=930097&view=diff ============================================================================== --- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-4.txt (original) +++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-6.txt Thu Apr 1 21:04:39 2010 @@ -1,3 +1,3 @@ <tr> - <td colspan="2"><div align="left"><button type="reset" name="myname" value="bar">mylabel</button></div></td> -</tr> + <td colspan="2"><div align="right"><button type="reset" name="myname" value="bar"><img alt="mylabel" src="some.gif"/></button></div></td> +</tr> \ No newline at end of file Added: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-7.txt URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-7.txt?rev=930097&view=auto ============================================================================== --- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-7.txt (added) +++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-7.txt Thu Apr 1 21:04:39 2010 @@ -0,0 +1 @@ +<button type="reset" name="action:manager!update" value="Reset">mylabel</button> \ No newline at end of file Added: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-8.txt URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-8.txt?rev=930097&view=auto ============================================================================== --- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-8.txt (added) +++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-8.txt Thu Apr 1 21:04:39 2010 @@ -0,0 +1 @@ +<button type="reset" name="action:manager" value="Reset">mylabel</button> \ No newline at end of file Added: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-9.txt URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-9.txt?rev=930097&view=auto ============================================================================== --- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-9.txt (added) +++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Reset-9.txt Thu Apr 1 21:04:39 2010 @@ -0,0 +1 @@ +<button type="reset" name="method:update" value="Reset">mylabel</button> \ No newline at end of file