Merge pull request #169 from burtonrhodes/checkbox_requiredValue

WW-4865: Add "requiredValue" parameter to Checkbox Struts Tag
This commit is contained in:
Aleksandr Mashchenko
2018-03-23 21:51:41 +02:00
committed by GitHub
14 changed files with 90 additions and 9 deletions
@@ -57,6 +57,7 @@ public class Checkbox extends UIBean {
final public static String TEMPLATE = "checkbox";
protected String fieldValue;
protected String submitUnchecked;
public Checkbox(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
@@ -72,6 +73,11 @@ public class Checkbox extends UIBean {
} else {
addParameter("fieldValue", "true");
}
if (submitUnchecked != null) {
addParameter("submitUnchecked", findString(submitUnchecked));
} else {
addParameter("submitUnchecked", "false");
}
}
protected Class getValueClassType() {
@@ -83,4 +89,8 @@ public class Checkbox extends UIBean {
this.fieldValue = fieldValue;
}
@StrutsTagAttribute(description="If set to true, unchecked elements will be submitted with the form.", defaultValue="false")
public void setSubmitUnchecked(String submitUnchecked) {
this.submitUnchecked = submitUnchecked;
}
}
@@ -34,6 +34,7 @@ public class CheckboxTag extends AbstractUITag {
private static final long serialVersionUID = -350752809266337636L;
protected String fieldValue;
protected String submitUnchecked;
public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
return new Checkbox(stack, req, res);
@@ -43,9 +44,14 @@ public class CheckboxTag extends AbstractUITag {
super.populateParams();
((Checkbox) component).setFieldValue(fieldValue);
((Checkbox) component).setSubmitUnchecked(submitUnchecked);
}
public void setFieldValue(String aValue) {
this.fieldValue = aValue;
}
public void setSubmitUnchecked(String aValue) {
this.submitUnchecked = aValue;
}
}
@@ -38,8 +38,11 @@
<#include "/${parameters.templateDir}/${parameters.expandTheme}/scripting-events.ftl" />
<#include "/${parameters.templateDir}/${parameters.expandTheme}/common-attributes.ftl" />
<#include "/${parameters.templateDir}/${parameters.expandTheme}/dynamic-attributes.ftl" />
/><input type="hidden" id="__checkbox_${parameters.id?html}" name="__checkbox_${parameters.name?html}" value="${parameters.fieldValue?html}"<#rt/>
/>
<#if (parameters.submitUnchecked?boolean)!false>
<input type="hidden" id="__checkbox_${parameters.id?html}" name="__checkbox_${parameters.name?html}" value="${parameters.fieldValue?html}"<#rt/>
<#if parameters.disabled!false>
disabled="disabled"<#rt/>
</#if>
/>
/>
</#if>
@@ -297,6 +297,14 @@ Please do not edit it directly.
<td align="left" valign="top">String</td>
<td align="left" valign="top">The css style definitions for element to use - it's an alias of cssStyle attribute.</td>
</tr>
<tr>
<td align="left" valign="top">submitUnchecked</td>
<td align="left" valign="top">false</td>
<td align="left" valign="top">false</td>
<td align="left" valign="top">false</td>
<td align="left" valign="top">String</td>
<td align="left" valign="top">If set to true, unchecked elements will be submitted with the form.</td>
</tr>
<tr>
<td align="left" valign="top">tabindex</td>
<td align="left" valign="top">false</td>
@@ -194,4 +194,48 @@ public class CheckboxTest extends AbstractUITagTest {
verify(CheckboxTag.class.getResource("Checkbox-6.txt"));
}
public void testSubmitUncheckedAsFalse() throws Exception {
TestAction testAction = (TestAction) action;
testAction.setFoo("true");
CheckboxTag tag = new CheckboxTag();
tag.setPageContext(pageContext);
tag.setLabel("mylabel");
tag.setName("foo");
tag.setFieldValue("baz");
//tag.setSubmitUnchecked("false"); // Test default value
tag.setTitle("mytitle");
tag.setDisabled("true");
tag.doStartTag();
tag.doEndTag();
verify(CheckboxTag.class.getResource("Checkbox-7.txt"));
// Test value set
tag.setSubmitUnchecked("false");
verify(CheckboxTag.class.getResource("Checkbox-7.txt"));
}
public void testSubmitUncheckedAsTrue() throws Exception {
TestAction testAction = (TestAction) action;
testAction.setFoo("true");
CheckboxTag tag = new CheckboxTag();
tag.setPageContext(pageContext);
tag.setLabel("mylabel");
tag.setName("foo");
tag.setFieldValue("baz");
tag.setSubmitUnchecked("true");
tag.setTitle("mytitle");
tag.setDisabled("true");
tag.doStartTag();
tag.doEndTag();
verify(CheckboxTag.class.getResource("Checkbox-8.txt"));
}
}
@@ -3,7 +3,6 @@
</td>
<td class="tdCheckboxInput">
<input type="checkbox" name="foo" value="baz" checked="checked" id="someId" title="mytitle" onfocus="test();"/>
<input type="hidden" id="__checkbox_someId" name="__checkbox_foo" value="baz"/>
<label for="someId" class="checkboxLabel">mylabel</label>
</td>
</tr>
@@ -3,7 +3,6 @@
</td>
<td class="tdCheckboxInput">
<input type="checkbox" name="foo" value="baz" id="foo" title="mytitle"/>
<input type="hidden" id="__checkbox_foo" name="__checkbox_foo" value="baz"/>
<label for="foo" class="checkboxLabel">mylabel</label>
</td>
</tr>
@@ -10,7 +10,6 @@
</td>
<td class="tdCheckboxInput">
<input type="checkbox" name="foo" value="baz" checked="checked" id="foo" class="myErrorClass" title="mytitle" onclick="test();" ondblclick="test();"/>
<input type="hidden" id="__checkbox_foo" name="__checkbox_foo" value="baz"/>
<label for="foo" class="checkboxErrorLabel">mylabel</label>
</td>
</tr>
@@ -10,7 +10,6 @@
</td>
<td class="tdCheckboxInput">
<input type="checkbox" name="foo" value="baz" checked="checked" id="foo" style="color:red" title="mytitle" onclick="test();" ondblclick="test();"/>
<input type="hidden" id="__checkbox_foo" name="__checkbox_foo" value="baz"/>
<label for="foo" class="checkboxErrorLabel">mylabel</label>
</td>
</tr>
@@ -6,6 +6,5 @@
<tr>
<td colspan="2">
<input type="checkbox" name="foo" value="baz" checked="checked" id="someId" title="mytitle" onfocus="test();"/>
<input type="hidden" id="__checkbox_someId" name="__checkbox_foo" value="baz"/>
</td>
</tr>
@@ -4,6 +4,5 @@
</td>
<td class="tdCheckboxInput">
<input type="checkbox" name="foo" value="baz" checked="checked" id="someId" title="mytitle" onfocus="test();"/>
<input type="hidden" id="__checkbox_someId" name="__checkbox_foo" value="baz"/>
</td>
</tr>
@@ -3,7 +3,6 @@
</td>
<td class="tdCheckboxInput">
<input type="checkbox" name="foo" value="baz" checked="checked" disabled="disabled" id="foo" title="mytitle" />
<input type="hidden" id="__checkbox_foo" name="__checkbox_foo" value="baz" disabled="disabled"/>
<label for="foo" class="checkboxLabel">mylabel</label>
</td>
</tr>
@@ -0,0 +1,8 @@
<tr>
<td class="tdCheckboxLabel">
</td>
<td class="tdCheckboxInput">
<input type="checkbox" name="foo" value="baz" checked="checked" disabled="disabled" id="foo" title="mytitle"/>
<label for="foo" class="checkboxLabel">mylabel</label>
</td>
</tr>
@@ -0,0 +1,9 @@
<tr>
<td class="tdCheckboxLabel">
</td>
<td class="tdCheckboxInput">
<input type="checkbox" name="foo" value="baz" checked="checked" disabled="disabled" id="foo" title="mytitle"/>
<input type="hidden" id="__checkbox_foo" name="__checkbox_foo" value="baz" disabled="disabled"/>
<label for="foo" class="checkboxLabel">mylabel</label>
</td>
</tr>