use of org.springframework.web.servlet.support.BindStatus in project spring-framework by spring-projects.
the class OptionTagTests method withCustomObjectAndEditorSelected.
@Test
public void withCustomObjectAndEditorSelected() throws Exception {
final PropertyEditor floatEditor = new SimpleFloatEditor();
floatEditor.setValue(new Float("12.34"));
String selectName = "testBean.someNumber";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
@Override
public PropertyEditor getEditor() {
return floatEditor;
}
};
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
this.tag.setValue(new Float(12.34));
this.tag.setLabel("12.34f");
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertOptionTagOpened(output);
assertOptionTagClosed(output);
assertContainsAttribute(output, "selected", "selected");
assertBlockTagContains(output, "12.34f");
}
use of org.springframework.web.servlet.support.BindStatus in project spring-framework by spring-projects.
the class OptionTagTests method asBodyTagCollapsed.
@Test
public void asBodyTagCollapsed() throws Exception {
String selectName = "testBean.name";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
String bodyContent = "some content";
this.tag.setValue(bodyContent);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertOptionTagOpened(output);
assertOptionTagClosed(output);
assertContainsAttribute(output, "value", bodyContent);
assertBlockTagContains(output, bodyContent);
}
use of org.springframework.web.servlet.support.BindStatus in project spring-framework by spring-projects.
the class OptionTagTests method renderNotSelected.
@Test
public void renderNotSelected() throws Exception {
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();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertOptionTagOpened(output);
assertOptionTagClosed(output);
assertContainsAttribute(output, "value", "bar");
assertBlockTagContains(output, "Bar");
}
use of org.springframework.web.servlet.support.BindStatus in project spring-framework by spring-projects.
the class OptionsTagTests method withItemsNullReference.
@Test
public void withItemsNullReference() throws Exception {
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false));
this.tag.setItems(Collections.emptyList());
this.tag.setItemValue("isoCode");
this.tag.setItemLabel("name");
int result = this.tag.doStartTag();
assertEquals(Tag.SKIP_BODY, result);
String output = getOutput();
output = "<doc>" + output + "</doc>";
SAXReader reader = new SAXReader();
Document document = reader.read(new StringReader(output));
Element rootElement = document.getRootElement();
List children = rootElement.elements();
assertEquals("Incorrect number of children", 0, children.size());
}
use of org.springframework.web.servlet.support.BindStatus in project spring-framework by spring-projects.
the class OptionsTagTests method withCollection.
@Test
public void withCollection() throws Exception {
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false));
this.tag.setItems(Country.getCountries());
this.tag.setItemValue("isoCode");
this.tag.setItemLabel("name");
this.tag.setId("myOption");
this.tag.setCssClass("myClass");
this.tag.setOnclick("CLICK");
int result = this.tag.doStartTag();
assertEquals(Tag.SKIP_BODY, result);
String output = getOutput();
output = "<doc>" + output + "</doc>";
SAXReader reader = new SAXReader();
Document document = reader.read(new StringReader(output));
Element rootElement = document.getRootElement();
List children = rootElement.elements();
assertEquals("Incorrect number of children", 4, children.size());
Element element = (Element) rootElement.selectSingleNode("option[@value = 'UK']");
assertEquals("UK node not selected", "selected", element.attribute("selected").getValue());
assertEquals("myOption3", element.attribute("id").getValue());
assertEquals("myClass", element.attribute("class").getValue());
assertEquals("CLICK", element.attribute("onclick").getValue());
}
Aggregations