Author: musachy Date: Thu Dec 18 06:59:05 2008 New Revision: 727731 URL: http://svn.apache.org/viewvc?rev=727731&view=rev Log: Fix closing for submit tag
Modified: struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SubmitHandler.java struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SubmitTest.java Modified: struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SubmitHandler.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SubmitHandler.java?rev=727731&r1=727730&r2=727731&view=diff ============================================================================== --- struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SubmitHandler.java (original) +++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SubmitHandler.java Thu Dec 18 06:59:05 2008 @@ -35,7 +35,6 @@ Attributes attrs = new Attributes(); String type = TextUtils.noNull((String) params.get("type"), "input"); - String body = (String) params.get("body"); if ("button".equals(type)) { attrs.addIfExists("name", params.get("name")) @@ -48,18 +47,7 @@ .addIfExists("style", params.get("cssStyle")); start("button", attrs); - - //button body - if (TextUtils.stringSet(body)) - characters(body, false); - else if (params.containsKey("label")) { - String label = (String) params.get("label"); - if (TextUtils.stringSet(label)) - characters(label, false); - } } else if ("image".equals(type)) { - if (TextUtils.stringSet(body)) - characters(body, false); attrs.addIfExists("src", params.get("src"), false) .add("type", "image") .addIfExists("alt", params.get("label")); @@ -83,13 +71,24 @@ public void generate() throws IOException { Map<String, Object> params = context.getParameters(); Attributes attrs = new Attributes(); + String body = (String) params.get("body"); String type = TextUtils.noNull((String) params.get("type"), "input"); - if ("button".equals(type)) + if ("button".equals(type)) { + //button body + if (TextUtils.stringSet(body)) + characters(body, false); + else if (params.containsKey("label")) { + String label = (String) params.get("label"); + if (TextUtils.stringSet(label)) + characters(label, false); + } end("button"); - else if ("image".equals(type)) + } else if ("image".equals(type)) { + if (TextUtils.stringSet(body)) + characters(body, false); end("input"); - else + } else end("submit"); } } Modified: struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SubmitTest.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SubmitTest.java?rev=727731&r1=727730&r2=727731&view=diff ============================================================================== --- struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SubmitTest.java (original) +++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SubmitTest.java Thu Dec 18 06:59:05 2008 @@ -38,19 +38,21 @@ tag.setTitle("title"); tag.setLabel("some label"); tag.setType("button"); - tag.addParameter("body", "<span>hey hey hey, here I go now</span>"); - tag.evaluateParams(); map.putAll(tag.getParameters()); theme.renderTag(getTagName(), context); + + tag.addParameter("body", "<span>hey hey hey, here I go now</span>"); + map.clear(); + map.putAll(tag.getParameters()); theme.renderTag(getTagName() + "-close", context); String output = writer.getBuffer().toString(); String expected = s("<button name='name' type='submit' value='val1' tabindex='1' id='id1' class='class1' style='style1'><span>hey hey hey, here I go now</span></button>"); assertEquals(expected, output); } - public void testRenderButtonWithLabel() { + public void testRenderButtonWithLabel() { tag.setName("name"); tag.setValue("val1"); tag.setDisabled("true"); @@ -130,6 +132,25 @@ assertEquals(expected, output); } + public void testRenderButtonImageWithBody() { + tag.setSrc("http://somesource/image.gif"); + tag.setLabel("alt text"); + tag.setType("image"); + + + tag.evaluateParams(); + map.putAll(tag.getParameters()); + theme.renderTag(getTagName(), context); + map.clear(); + tag.setType("image"); + tag.addParameter("body", "<span>hey hey hey, here I go now</span>"); + map.putAll(tag.getParameters()); + theme.renderTag(getTagName() + "-close", context); + String output = writer.getBuffer().toString(); + String expected = s("<input src='http://somesource/image.gif' type='image' alt='alt text'><span>hey hey hey, here I go now</span></input>"); + assertEquals(expected, output); + } + @Override protected void setUp() throws Exception { super.setUp();