SPR-7943 Add interface for HDIV integration and delegate to it from JSP form tags.
This commit is contained in:
@@ -29,6 +29,8 @@ import org.springframework.web.servlet.support.BindStatus;
|
||||
public class OptionTagEnumTests extends AbstractHtmlElementTagTests {
|
||||
|
||||
private OptionTag tag;
|
||||
|
||||
private SelectTag parentTag;
|
||||
|
||||
protected void onSetUp() {
|
||||
this.tag = new OptionTag() {
|
||||
@@ -36,7 +38,14 @@ public class OptionTagEnumTests extends AbstractHtmlElementTagTests {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
};
|
||||
this.tag.setParent(new SelectTag());
|
||||
this.parentTag = new SelectTag() {
|
||||
public String getName() {
|
||||
// Should not be used other than to delegate to
|
||||
// RequestDataValueDataProcessor
|
||||
return "testName";
|
||||
}
|
||||
};
|
||||
this.tag.setParent(this.parentTag);
|
||||
this.tag.setPageContext(getPageContext());
|
||||
}
|
||||
|
||||
@@ -44,7 +53,8 @@ public class OptionTagEnumTests extends AbstractHtmlElementTagTests {
|
||||
GenericBean testBean = new GenericBean();
|
||||
testBean.setCustomEnum(CustomEnum.VALUE_1);
|
||||
getPageContext().getRequest().setAttribute("testBean", testBean);
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.customEnum", false));
|
||||
String selectName = "testBean.customEnum";
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||
|
||||
this.tag.setValue("VALUE_1");
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
|
||||
private OptionTag tag;
|
||||
|
||||
private SelectTag parentTag;
|
||||
|
||||
protected void onSetUp() {
|
||||
this.tag = new OptionTag() {
|
||||
@@ -56,13 +57,21 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
};
|
||||
this.tag.setParent(new SelectTag());
|
||||
this.parentTag = new SelectTag() {
|
||||
public String getName() {
|
||||
// Should not be used other than to delegate to
|
||||
// RequestDataValueDataProcessor
|
||||
return "testName";
|
||||
}
|
||||
};
|
||||
this.tag.setParent(this.parentTag);
|
||||
this.tag.setPageContext(getPageContext());
|
||||
}
|
||||
|
||||
|
||||
public void testCanBeDisabledEvenWhenSelected() throws Exception {
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.name", false));
|
||||
String selectName = "testBean.name";
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||
this.tag.setValue("bar");
|
||||
this.tag.setLabel("Bar");
|
||||
this.tag.setDisabled("true");
|
||||
@@ -81,7 +90,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
}
|
||||
|
||||
public void testRenderNotSelected() throws Exception {
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.name", false));
|
||||
String selectName = "testBean.name";
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||
this.tag.setValue("bar");
|
||||
this.tag.setLabel("Bar");
|
||||
int result = this.tag.doStartTag();
|
||||
@@ -101,7 +111,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
String dynamicAttribute1 = "attr1";
|
||||
String dynamicAttribute2 = "attr2";
|
||||
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.name", false));
|
||||
String selectName = "testBean.name";
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||
this.tag.setValue("bar");
|
||||
this.tag.setLabel("Bar");
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);
|
||||
@@ -123,7 +134,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
}
|
||||
|
||||
public void testRenderSelected() throws Exception {
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.name", false));
|
||||
String selectName = "testBean.name";
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||
this.tag.setId("myOption");
|
||||
this.tag.setValue("foo");
|
||||
this.tag.setLabel("Foo");
|
||||
@@ -143,7 +155,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
}
|
||||
|
||||
public void testWithNoLabel() throws Exception {
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.name", false));
|
||||
String selectName = "testBean.name";
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||
this.tag.setValue("bar");
|
||||
this.tag.setCssClass("myClass");
|
||||
this.tag.setOnclick("CLICK");
|
||||
@@ -175,7 +188,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
}
|
||||
|
||||
public void testWithEnum() throws Exception {
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.favouriteColour", false));
|
||||
String selectName = "testBean.favouriteColour";
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||
|
||||
String value = Colour.GREEN.getCode().toString();
|
||||
String label = Colour.GREEN.getLabel();
|
||||
@@ -198,7 +212,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
}
|
||||
|
||||
public void testWithEnumNotSelected() throws Exception {
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.favouriteColour", false));
|
||||
String selectName = "testBean.favouriteColour";
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||
|
||||
String value = Colour.BLUE.getCode().toString();
|
||||
String label = Colour.BLUE.getLabel();
|
||||
@@ -221,7 +236,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
}
|
||||
|
||||
public void testWithPropertyEditor() throws Exception {
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.stringArray", false) {
|
||||
String selectName = "testBean.stringArray";
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
|
||||
public PropertyEditor getEditor() {
|
||||
return new StringArrayPropertyEditor();
|
||||
}
|
||||
@@ -249,7 +265,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
public void testWithPropertyEditorStringComparison() throws Exception {
|
||||
final PropertyEditor testBeanEditor = new TestBeanPropertyEditor();
|
||||
testBeanEditor.setValue(new TestBean("Sally"));
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.spouse", false) {
|
||||
String selectName = "testBean.spouse";
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
|
||||
public PropertyEditor getEditor() {
|
||||
return testBeanEditor;
|
||||
}
|
||||
@@ -272,7 +289,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
}
|
||||
|
||||
public void testWithCustomObjectSelected() throws Exception {
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.someNumber", false));
|
||||
String selectName = "testBean.someNumber";
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||
this.tag.setValue("${myNumber}");
|
||||
this.tag.setLabel("GBP ${myNumber}");
|
||||
int result = this.tag.doStartTag();
|
||||
@@ -290,7 +308,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
}
|
||||
|
||||
public void testWithCustomObjectNotSelected() throws Exception {
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.someNumber", false));
|
||||
String selectName = "testBean.someNumber";
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||
this.tag.setValue("${myOtherNumber}");
|
||||
this.tag.setLabel("GBP ${myOtherNumber}");
|
||||
int result = this.tag.doStartTag();
|
||||
@@ -310,7 +329,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
public void testWithCustomObjectAndEditorSelected() throws Exception {
|
||||
final PropertyEditor floatEditor = new SimpleFloatEditor();
|
||||
floatEditor.setValue(new Float("12.34"));
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.someNumber", false) {
|
||||
String selectName = "testBean.someNumber";
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
|
||||
public PropertyEditor getEditor() {
|
||||
return floatEditor;
|
||||
}
|
||||
@@ -334,7 +354,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
|
||||
public void testWithCustomObjectAndEditorNotSelected() throws Exception {
|
||||
final PropertyEditor floatEditor = new SimpleFloatEditor();
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.someNumber", false) {
|
||||
String selectName = "testBean.someNumber";
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
|
||||
public PropertyEditor getEditor() {
|
||||
return floatEditor;
|
||||
}
|
||||
@@ -357,7 +378,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
}
|
||||
|
||||
public void testAsBodyTag() throws Exception {
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.name", false);
|
||||
String selectName = "testBean.name";
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
|
||||
|
||||
String bodyContent = "some content";
|
||||
@@ -377,7 +399,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
}
|
||||
|
||||
public void testAsBodyTagSelected() throws Exception {
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.name", false);
|
||||
String selectName = "testBean.name";
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
|
||||
|
||||
String bodyContent = "some content";
|
||||
@@ -396,7 +419,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
}
|
||||
|
||||
public void testAsBodyTagCollapsed() throws Exception {
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.name", false);
|
||||
String selectName = "testBean.name";
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
|
||||
|
||||
String bodyContent = "some content";
|
||||
@@ -416,7 +440,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
}
|
||||
|
||||
public void testAsBodyTagWithEditor() throws Exception {
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.stringArray", false) {
|
||||
String selectName = "testBean.stringArray";
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
|
||||
public PropertyEditor getEditor() {
|
||||
return new RulesVariantEditor();
|
||||
}
|
||||
|
||||
@@ -64,6 +64,11 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
public String getName() {
|
||||
// Should not be used other than to delegate to
|
||||
// RequestDataValueDataProcessor
|
||||
return "testName";
|
||||
}
|
||||
};
|
||||
selectTag.setPageContext(getPageContext());
|
||||
this.tag.setParent(selectTag);
|
||||
@@ -299,5 +304,5 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
|
||||
RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
|
||||
pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -33,11 +33,11 @@ public class RedirectViewUriTemplateTests {
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
private MockHttpServletResponse response;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
request = new MockHttpServletRequest();
|
||||
response = new MockHttpServletResponse();
|
||||
this.request = new MockHttpServletRequest();
|
||||
this.response = new MockHttpServletResponse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -47,9 +47,9 @@ public class RedirectViewUriTemplateTests {
|
||||
|
||||
String baseUrl = "http://url.somewhere.com";
|
||||
RedirectView redirectView = new RedirectView(baseUrl + "/{foo}");
|
||||
redirectView.renderMergedOutputModel(model, request, response);
|
||||
redirectView.renderMergedOutputModel(model, this.request, this.response);
|
||||
|
||||
assertEquals(baseUrl + "/bar", response.getRedirectedUrl());
|
||||
assertEquals(baseUrl + "/bar", this.response.getRedirectedUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,9 +59,9 @@ public class RedirectViewUriTemplateTests {
|
||||
|
||||
String baseUrl = "http://url.somewhere.com";
|
||||
RedirectView redirectView = new RedirectView(baseUrl + "/context path/{foo}");
|
||||
redirectView.renderMergedOutputModel(model, request, response);
|
||||
redirectView.renderMergedOutputModel(model, this.request, this.response);
|
||||
|
||||
assertEquals(baseUrl + "/context path/bar%2Fbar%20baz", response.getRedirectedUrl());
|
||||
assertEquals(baseUrl + "/context path/bar%2Fbar%20baz", this.response.getRedirectedUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,9 +71,9 @@ public class RedirectViewUriTemplateTests {
|
||||
model.put("fooArr", new String[] { "baz", "bazz" });
|
||||
|
||||
RedirectView redirectView = new RedirectView("/foo/{foo}");
|
||||
redirectView.renderMergedOutputModel(model, request, response);
|
||||
redirectView.renderMergedOutputModel(model, this.request, this.response);
|
||||
|
||||
assertEquals("/foo/bar?fooArr=baz&fooArr=bazz", response.getRedirectedUrl());
|
||||
assertEquals("/foo/bar?fooArr=baz&fooArr=bazz", this.response.getRedirectedUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,9 +82,9 @@ public class RedirectViewUriTemplateTests {
|
||||
model.put("foo", new Long(611));
|
||||
|
||||
RedirectView redirectView = new RedirectView("/foo/{foo}");
|
||||
redirectView.renderMergedOutputModel(model, request, response);
|
||||
redirectView.renderMergedOutputModel(model, this.request, this.response);
|
||||
|
||||
assertEquals("/foo/611", response.getRedirectedUrl());
|
||||
assertEquals("/foo/611", this.response.getRedirectedUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,18 +98,18 @@ public class RedirectViewUriTemplateTests {
|
||||
currentRequestUriTemplateVars.put("var1", "v1");
|
||||
currentRequestUriTemplateVars.put("name", "v2");
|
||||
currentRequestUriTemplateVars.put("var3", "v3");
|
||||
request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, currentRequestUriTemplateVars);
|
||||
this.request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, currentRequestUriTemplateVars);
|
||||
|
||||
String url = "http://url.somewhere.com";
|
||||
RedirectView redirectView = new RedirectView(url + "/{key1}/{var1}/{name}");
|
||||
redirectView.renderMergedOutputModel(model, request, response);
|
||||
redirectView.renderMergedOutputModel(model, this.request, this.response);
|
||||
|
||||
assertEquals(url + "/value1/v1/value2?key3=value3", response.getRedirectedUrl());
|
||||
assertEquals(url + "/value1/v1/value2?key3=value3", this.response.getRedirectedUrl());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void uriTemplateNullValue() throws Exception {
|
||||
new RedirectView("/{foo}").renderMergedOutputModel(new ModelMap(), request, response);
|
||||
new RedirectView("/{foo}").renderMergedOutputModel(new ModelMap(), this.request, this.response);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,9 +117,9 @@ public class RedirectViewUriTemplateTests {
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
|
||||
RedirectView redirectView = new RedirectView("");
|
||||
redirectView.renderMergedOutputModel(model, request, response);
|
||||
redirectView.renderMergedOutputModel(model, this.request, this.response);
|
||||
|
||||
assertEquals("", response.getRedirectedUrl());
|
||||
assertEquals("", this.response.getRedirectedUrl());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
import org.springframework.web.servlet.View;
|
||||
import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
|
||||
import org.springframework.web.servlet.support.RequestDataValueProcessor;
|
||||
import org.springframework.web.servlet.view.AbstractView;
|
||||
|
||||
/**
|
||||
@@ -148,6 +149,8 @@ public class VelocityViewTests {
|
||||
expectLastCall().andReturn(null);
|
||||
wac.getServletContext();
|
||||
expectLastCall().andReturn(sc).times(3);
|
||||
wac.getBean("requestDataValueProcessor", RequestDataValueProcessor.class);
|
||||
expectLastCall().andReturn(null);
|
||||
replay(wac);
|
||||
|
||||
HttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -203,6 +206,8 @@ public class VelocityViewTests {
|
||||
expectLastCall().andReturn(null);
|
||||
wac.getServletContext();
|
||||
expectLastCall().andReturn(sc).times(3);
|
||||
wac.getBean("requestDataValueProcessor", RequestDataValueProcessor.class);
|
||||
expectLastCall().andReturn(null);
|
||||
replay(wac);
|
||||
|
||||
HttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
Reference in New Issue
Block a user