SPR-8661 Add disabled attribute to HiddenInputTag
This commit is contained in:
parent
78fbceff82
commit
bba8bb6ec0
|
|
@ -19,6 +19,7 @@ Changes in version 3.1 RC2 (2011-11-15)
|
||||||
* Support target request with multiple parameter values in FlahMap matching logic
|
* Support target request with multiple parameter values in FlahMap matching logic
|
||||||
* Fix issue in SimpleMappingExceptionResolver causing exception when setting "statusCodes" property
|
* Fix issue in SimpleMappingExceptionResolver causing exception when setting "statusCodes" property
|
||||||
* The Form input tag allows type values other than "text" such as HTML5-specific types.
|
* The Form input tag allows type values other than "text" such as HTML5-specific types.
|
||||||
|
* The Form hidden tag supports "disabled" attribute
|
||||||
|
|
||||||
Changes in version 3.1 RC1 (2011-10-11)
|
Changes in version 3.1 RC1 (2011-10-11)
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,28 @@ import javax.servlet.jsp.JspException;
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class HiddenInputTag extends AbstractHtmlElementTag {
|
public class HiddenInputTag extends AbstractHtmlElementTag {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the '<code>disabled</code>' attribute.
|
||||||
|
*/
|
||||||
|
public static final String DISABLED_ATTRIBUTE = "disabled";
|
||||||
|
|
||||||
|
private String disabled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of the '<code>disabled</code>' attribute.
|
||||||
|
*/
|
||||||
|
public String getDisabled() {
|
||||||
|
return this.disabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the value of the '<code>disabled</code>' attribute.
|
||||||
|
* May be a runtime expression.
|
||||||
|
*/
|
||||||
|
public void setDisabled(String disabled) {
|
||||||
|
this.disabled = disabled;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flags "type" as an illegal dynamic attribute.
|
* Flags "type" as an illegal dynamic attribute.
|
||||||
*/
|
*/
|
||||||
|
|
@ -54,10 +76,20 @@ public class HiddenInputTag extends AbstractHtmlElementTag {
|
||||||
tagWriter.startTag("input");
|
tagWriter.startTag("input");
|
||||||
writeDefaultAttributes(tagWriter);
|
writeDefaultAttributes(tagWriter);
|
||||||
tagWriter.writeAttribute("type", "hidden");
|
tagWriter.writeAttribute("type", "hidden");
|
||||||
|
if (isDisabled()) {
|
||||||
|
tagWriter.writeAttribute(DISABLED_ATTRIBUTE, "disabled");
|
||||||
|
}
|
||||||
String value = getDisplayString(getBoundValue(), getPropertyEditor());
|
String value = getDisplayString(getBoundValue(), getPropertyEditor());
|
||||||
tagWriter.writeAttribute("value", processFieldValue(getName(), value, "hidden"));
|
tagWriter.writeAttribute("value", processFieldValue(getName(), value, "hidden"));
|
||||||
tagWriter.endTag();
|
tagWriter.endTag();
|
||||||
return SKIP_BODY;
|
return SKIP_BODY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the current HTML tag disabled?
|
||||||
|
*/
|
||||||
|
protected boolean isDisabled() throws JspException {
|
||||||
|
return evaluateBoolean(DISABLED_ATTRIBUTE, getDisabled());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -652,6 +652,12 @@
|
||||||
<required>false</required>
|
<required>false</required>
|
||||||
<rtexprvalue>true</rtexprvalue>
|
<rtexprvalue>true</rtexprvalue>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<attribute>
|
||||||
|
<description>HTML Optional Attribute. Setting the value of this attribute to 'true' (without the quotes) will disable the HTML element.</description>
|
||||||
|
<name>disabled</name>
|
||||||
|
<required>false</required>
|
||||||
|
<rtexprvalue>true</rtexprvalue>
|
||||||
|
</attribute>
|
||||||
<attribute>
|
<attribute>
|
||||||
<description>HTML Event Attribute</description>
|
<description>HTML Event Attribute</description>
|
||||||
<name>onclick</name>
|
<name>onclick</name>
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,12 @@
|
||||||
|
|
||||||
package org.springframework.web.servlet.tags.form;
|
package org.springframework.web.servlet.tags.form;
|
||||||
|
|
||||||
import org.springframework.beans.TestBean;
|
|
||||||
import org.springframework.validation.BeanPropertyBindingResult;
|
|
||||||
|
|
||||||
import javax.servlet.jsp.JspException;
|
import javax.servlet.jsp.JspException;
|
||||||
import javax.servlet.jsp.tagext.Tag;
|
import javax.servlet.jsp.tagext.Tag;
|
||||||
|
|
||||||
|
import org.springframework.beans.TestBean;
|
||||||
|
import org.springframework.validation.BeanPropertyBindingResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
*/
|
*/
|
||||||
|
|
@ -31,6 +31,7 @@ public class HiddenInputTagTests extends AbstractFormTagTests {
|
||||||
|
|
||||||
private TestBean bean;
|
private TestBean bean;
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
protected void onSetUp() {
|
protected void onSetUp() {
|
||||||
this.tag = new HiddenInputTag() {
|
this.tag = new HiddenInputTag() {
|
||||||
protected TagWriter createTagWriter() {
|
protected TagWriter createTagWriter() {
|
||||||
|
|
@ -52,6 +53,7 @@ public class HiddenInputTagTests extends AbstractFormTagTests {
|
||||||
|
|
||||||
assertContainsAttribute(output, "type", "hidden");
|
assertContainsAttribute(output, "type", "hidden");
|
||||||
assertContainsAttribute(output, "value", "Sally Greenwood");
|
assertContainsAttribute(output, "value", "Sally Greenwood");
|
||||||
|
assertAttributeNotPresent(output, "disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithCustomBinder() throws Exception {
|
public void testWithCustomBinder() throws Exception {
|
||||||
|
|
@ -82,6 +84,34 @@ public class HiddenInputTagTests extends AbstractFormTagTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testDisabledTrue() throws Exception {
|
||||||
|
this.tag.setDisabled("true");
|
||||||
|
|
||||||
|
this.tag.doStartTag();
|
||||||
|
this.tag.doEndTag();
|
||||||
|
|
||||||
|
String output = getOutput();
|
||||||
|
assertTagOpened(output);
|
||||||
|
assertTagClosed(output);
|
||||||
|
|
||||||
|
assertContainsAttribute(output, "disabled", "disabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
// SPR-8661
|
||||||
|
|
||||||
|
public void testDisabledFalse() throws Exception {
|
||||||
|
this.tag.setDisabled("false");
|
||||||
|
|
||||||
|
this.tag.doStartTag();
|
||||||
|
this.tag.doEndTag();
|
||||||
|
|
||||||
|
String output = getOutput();
|
||||||
|
assertTagOpened(output);
|
||||||
|
assertTagClosed(output);
|
||||||
|
|
||||||
|
assertAttributeNotPresent(output, "disabled");
|
||||||
|
}
|
||||||
|
|
||||||
private void assertTagClosed(String output) {
|
private void assertTagClosed(String output) {
|
||||||
assertTrue(output.endsWith("/>"));
|
assertTrue(output.endsWith("/>"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue