SPR-4700 - Add single checkbox input macro for Velocity and Freemarker
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1689 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
31938a1dec
commit
809b1d2c4f
|
|
@ -296,6 +296,23 @@
|
||||||
<input type="hidden" name="_${status.expression}" value="on"/>
|
<input type="hidden" name="_${status.expression}" value="on"/>
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
||||||
|
<#--
|
||||||
|
* formCheckbox
|
||||||
|
*
|
||||||
|
* Show a single checkbox.
|
||||||
|
*
|
||||||
|
* @param path the name of the field to bind to
|
||||||
|
* @param attributes any additional attributes for the element (such as class
|
||||||
|
* or CSS styles or size
|
||||||
|
-->
|
||||||
|
<#macro formCheckbox path attributes="">
|
||||||
|
<@bind path />
|
||||||
|
<#local checked><#if status.value?? && status.value?string=="true">true<#else>false</#if></#local>
|
||||||
|
<#local id><#if status.expression??>${status.expression}<#else>${path}</#if></#local>
|
||||||
|
<input type="hidden" name="_${id}" value="on"/>
|
||||||
|
<input type="checkbox" id="${id}" name="${id}" checked="${checked}" ${attributes}/>
|
||||||
|
</#macro>
|
||||||
|
|
||||||
<#--
|
<#--
|
||||||
* showErrors
|
* showErrors
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -269,6 +269,21 @@
|
||||||
<input type="hidden" name="_${status.expression}" value="on"/>
|
<input type="hidden" name="_${status.expression}" value="on"/>
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
#**
|
||||||
|
* springFormCheckbox
|
||||||
|
*
|
||||||
|
* Show a single checkbox.
|
||||||
|
*
|
||||||
|
* @param path the name of the field to bind to
|
||||||
|
* @param attributes any additional attributes for the element (such as class
|
||||||
|
* or CSS styles or size
|
||||||
|
*#
|
||||||
|
#macro( springFormCheckbox $path $attributes )
|
||||||
|
#springBind($path)
|
||||||
|
<input type="hidden" name="_${status.expression}" value="on"/>
|
||||||
|
<input type="checkbox" id="${status.expression}" name="${status.expression}" checked="#if("$!{status.value}"=="true")true#{else}false#end" ${attributes}/>
|
||||||
|
#end
|
||||||
|
|
||||||
#**
|
#**
|
||||||
* springShowErrors
|
* springShowErrors
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,7 @@ public class FreeMarkerMacroTests extends TestCase {
|
||||||
|
|
||||||
TestBean tb = new TestBean("Darren", 99);
|
TestBean tb = new TestBean("Darren", 99);
|
||||||
tb.setSpouse(new TestBean("Fred"));
|
tb.setSpouse(new TestBean("Fred"));
|
||||||
|
tb.setJedi(true);
|
||||||
request.setAttribute("command", tb);
|
request.setAttribute("command", tb);
|
||||||
|
|
||||||
HashMap names = new HashMap();
|
HashMap names = new HashMap();
|
||||||
|
|
@ -192,6 +193,10 @@ public class FreeMarkerMacroTests extends TestCase {
|
||||||
if (tokens[i].equals("FORM11")) assertEquals("<input type=\"text\" id=\"name\" name=\"name\" value=\"Darren\" >", tokens[i + 1]);
|
if (tokens[i].equals("FORM11")) assertEquals("<input type=\"text\" id=\"name\" name=\"name\" value=\"Darren\" >", tokens[i + 1]);
|
||||||
if (tokens[i].equals("FORM12")) assertEquals("<input type=\"hidden\" id=\"name\" name=\"name\" value=\"Darren\" >", tokens[i + 1]);
|
if (tokens[i].equals("FORM12")) assertEquals("<input type=\"hidden\" id=\"name\" name=\"name\" value=\"Darren\" >", tokens[i + 1]);
|
||||||
if (tokens[i].equals("FORM13")) assertEquals("<input type=\"password\" id=\"name\" name=\"name\" value=\"\" >", tokens[i + 1]);
|
if (tokens[i].equals("FORM13")) assertEquals("<input type=\"password\" id=\"name\" name=\"name\" value=\"\" >", tokens[i + 1]);
|
||||||
|
if (tokens[i].equals("FORM15")) assertEquals("<input type=\"hidden\" name=\"_name\" value=\"on\"/>", tokens[i + 1]);
|
||||||
|
if (tokens[i].equals("FORM15")) assertEquals("<input type=\"checkbox\" id=\"name\" name=\"name\" checked=\"false\" />", tokens[i + 2]);
|
||||||
|
if (tokens[i].equals("FORM16")) assertEquals("<input type=\"hidden\" name=\"_jedi\" value=\"on\"/>", tokens[i + 1]);
|
||||||
|
if (tokens[i].equals("FORM16")) assertEquals("<input type=\"checkbox\" id=\"jedi\" name=\"jedi\" checked=\"true\" />", tokens[i + 2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,3 +77,9 @@ FORM13
|
||||||
|
|
||||||
FORM14
|
FORM14
|
||||||
<@spring.formSingleSelect "command.name", options, ""/>
|
<@spring.formSingleSelect "command.name", options, ""/>
|
||||||
|
|
||||||
|
FORM15
|
||||||
|
<@spring.formCheckbox "command.name"/>
|
||||||
|
|
||||||
|
FORM16
|
||||||
|
<@spring.formCheckbox "command.jedi"/>
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,7 @@ public class VelocityMacroTests extends TestCase {
|
||||||
rc.setContextPath("/springtest");
|
rc.setContextPath("/springtest");
|
||||||
|
|
||||||
TestBean tb = new TestBean("Darren", 99);
|
TestBean tb = new TestBean("Darren", 99);
|
||||||
|
tb.setJedi(true);
|
||||||
request.setAttribute("command", tb);
|
request.setAttribute("command", tb);
|
||||||
|
|
||||||
HashMap names = new HashMap();
|
HashMap names = new HashMap();
|
||||||
|
|
@ -178,6 +179,10 @@ public class VelocityMacroTests extends TestCase {
|
||||||
//TODO verify remaining output (fix whitespace)
|
//TODO verify remaining output (fix whitespace)
|
||||||
if (tokens[i].equals("FORM9")) assertEquals("<input type=\"password\" id=\"name\" name=\"name\" value=\"\" >", tokens[i + 1]);
|
if (tokens[i].equals("FORM9")) assertEquals("<input type=\"password\" id=\"name\" name=\"name\" value=\"\" >", tokens[i + 1]);
|
||||||
if (tokens[i].equals("FORM10")) assertEquals("<input type=\"hidden\" id=\"name\" name=\"name\" value=\"Darren\" >", tokens[i + 1]);
|
if (tokens[i].equals("FORM10")) assertEquals("<input type=\"hidden\" id=\"name\" name=\"name\" value=\"Darren\" >", tokens[i + 1]);
|
||||||
|
if (tokens[i].equals("FORM15")) assertEquals("<input type=\"hidden\" name=\"_name\" value=\"on\"/>", tokens[i + 1]);
|
||||||
|
if (tokens[i].equals("FORM15")) assertEquals("<input type=\"checkbox\" id=\"name\" name=\"name\" checked=\"false\" />", tokens[i + 2]);
|
||||||
|
if (tokens[i].equals("FORM16")) assertEquals("<input type=\"hidden\" name=\"_jedi\" value=\"on\"/>", tokens[i + 1]);
|
||||||
|
if (tokens[i].equals("FORM16")) assertEquals("<input type=\"checkbox\" id=\"jedi\" name=\"jedi\" checked=\"true\" />", tokens[i + 2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,5 +53,12 @@ FORM9
|
||||||
FORM10
|
FORM10
|
||||||
#springFormHiddenInput("command.name" "")
|
#springFormHiddenInput("command.name" "")
|
||||||
|
|
||||||
|
FORM15
|
||||||
|
#springFormCheckbox("command.name" "")
|
||||||
|
|
||||||
|
FORM16
|
||||||
|
#springFormCheckbox("command.jedi" "")
|
||||||
|
|
||||||
|
|
||||||
ERRORS
|
ERRORS
|
||||||
#springShowErrors(" " "")
|
#springShowErrors(" " "")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue