SPR-8694 HTML5 updates to the "type" attribute of the Spring Form tags.
Since dynamic attributes were allowed in Spring 3, it raised the possibility to specify a type attribute on a number of the form tags. Where it makes sense (see below) that attribute is now rejected and reversely where it makes sense it is accepted. InputTag allows types other than "text" but rejects type="radio" or type="checkbox" since there is a good reason for those to be used only in conjunction with the appropriate form library tags. Other HTML input tags such as PasswordTag, HiddenInputTag, Checkbox(es)Tag and RadioBox(es)Tag check the dynamic attributes and reject them if they contain a type attribute since.
This commit is contained in:
@@ -24,6 +24,8 @@ import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.tagext.Tag;
|
||||
|
||||
import org.dom4j.Document;
|
||||
@@ -610,6 +612,18 @@ public class CheckboxTagTests extends AbstractFormTagTests {
|
||||
assertEquals("checked", checkboxElement.attribute("checked").getValue());
|
||||
assertEquals("true", checkboxElement.attribute("value").getValue());
|
||||
}
|
||||
|
||||
public void testDynamicTypeAttribute() throws JspException {
|
||||
try {
|
||||
this.tag.setDynamicAttribute(null, "type", "email");
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Attribute type=\"email\" is not allowed", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Date getDate() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.YEAR, 10);
|
||||
|
||||
@@ -28,6 +28,8 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.tagext.Tag;
|
||||
|
||||
import org.dom4j.Document;
|
||||
@@ -703,6 +705,17 @@ public class CheckboxesTagTests extends AbstractFormTagTests {
|
||||
assertEquals("element", spanElement.getName());
|
||||
}
|
||||
|
||||
public void testDynamicTypeAttribute() throws JspException {
|
||||
try {
|
||||
this.tag.setDynamicAttribute(null, "type", "email");
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Attribute type=\"email\" is not allowed", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Date getDate() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.YEAR, 10);
|
||||
|
||||
@@ -19,6 +19,7 @@ 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.tagext.Tag;
|
||||
|
||||
/**
|
||||
@@ -70,6 +71,16 @@ public class HiddenInputTagTests extends AbstractFormTagTests {
|
||||
assertContainsAttribute(output, "type", "hidden");
|
||||
assertContainsAttribute(output, "value", "12.34f");
|
||||
}
|
||||
|
||||
public void testDynamicTypeAttribute() throws JspException {
|
||||
try {
|
||||
this.tag.setDynamicAttribute(null, "type", "email");
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Attribute type=\"email\" is not allowed", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void assertTagClosed(String output) {
|
||||
assertTrue(output.endsWith("/>"));
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.web.servlet.tags.form;
|
||||
|
||||
import java.io.Writer;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.tagext.Tag;
|
||||
|
||||
import org.springframework.beans.TestBean;
|
||||
@@ -342,7 +343,40 @@ public class InputTagTests extends AbstractFormTagTests {
|
||||
assertValueAttribute(output, "Rob");
|
||||
}
|
||||
|
||||
public void testDynamicTypeAttribute() throws JspException {
|
||||
this.tag.setPath("myFloat");
|
||||
this.tag.setDynamicAttribute(null, "type", "number");
|
||||
|
||||
assertEquals(Tag.SKIP_BODY, this.tag.doStartTag());
|
||||
|
||||
String output = getOutput();
|
||||
assertTagOpened(output);
|
||||
assertTagClosed(output);
|
||||
|
||||
assertContainsAttribute(output, "type", "number");
|
||||
assertValueAttribute(output, "12.34");
|
||||
}
|
||||
|
||||
public void testDynamicTypeRadioAttribute() throws JspException {
|
||||
try {
|
||||
this.tag.setDynamicAttribute(null, "type", "radio");
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Attribute type=\"radio\" is not allowed", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testDynamicTypeCheckboxAttribute() throws JspException {
|
||||
try {
|
||||
this.tag.setDynamicAttribute(null, "type", "checkbox");
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Attribute type=\"checkbox\" is not allowed", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected final void assertTagClosed(String output) {
|
||||
assertTrue("Tag not closed properly", output.endsWith("/>"));
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.web.servlet.tags.form;
|
||||
|
||||
import java.io.Writer;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.tagext.Tag;
|
||||
|
||||
/**
|
||||
@@ -77,6 +78,15 @@ public class PasswordInputTagTests extends InputTagTests {
|
||||
assertValueAttribute(output, "");
|
||||
}
|
||||
|
||||
public void testDynamicTypeAttribute() throws JspException {
|
||||
try {
|
||||
this.getTag().setDynamicAttribute(null, "type", "email");
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Attribute type=\"email\" is not allowed", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertValueAttribute(String output, String expectedValue) {
|
||||
if (this.getPasswordTag().isShowPassword()) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.beans.PropertyEditorSupport;
|
||||
import java.io.StringReader;
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.tagext.Tag;
|
||||
|
||||
import org.dom4j.Document;
|
||||
@@ -227,6 +228,16 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
|
||||
assertEquals("checked", checkboxElement.attribute("checked").getValue());
|
||||
}
|
||||
|
||||
public void testDynamicTypeAttribute() throws JspException {
|
||||
try {
|
||||
this.tag.setDynamicAttribute(null, "type", "email");
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Attribute type=\"email\" is not allowed", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void assertTagOpened(String output) {
|
||||
assertTrue(output.indexOf("<input ") > -1);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.tagext.Tag;
|
||||
|
||||
import org.dom4j.Document;
|
||||
@@ -559,6 +560,16 @@ public final class RadioButtonsTagTests extends AbstractFormTagTests {
|
||||
assertEquals("element", spanElement.getName());
|
||||
}
|
||||
|
||||
public void testDynamicTypeAttribute() throws JspException {
|
||||
try {
|
||||
this.tag.setDynamicAttribute(null, "type", "email");
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Attribute type=\"email\" is not allowed", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private Date getDate() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.YEAR, 10);
|
||||
|
||||
Reference in New Issue
Block a user