use of org.springframework.web.servlet.support.BindStatus in project spring-framework by spring-projects.
the class OptionTagTests method withPropertyEditorStringComparison.
@Test
public void withPropertyEditorStringComparison() throws Exception {
final PropertyEditor testBeanEditor = new TestBeanPropertyEditor();
testBeanEditor.setValue(new TestBean("Sally"));
String selectName = "testBean.spouse";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
@Override
public PropertyEditor getEditor() {
return testBeanEditor;
}
};
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
this.tag.setValue("Sally");
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", "Sally");
assertContainsAttribute(output, "selected", "selected");
assertBlockTagContains(output, "Sally");
}
use of org.springframework.web.servlet.support.BindStatus in project spring-framework by spring-projects.
the class OptionTagTests method asBodyTagWithEditor.
@Test
public void asBodyTagWithEditor() throws Exception {
String selectName = "testBean.stringArray";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
@Override
public PropertyEditor getEditor() {
return new RulesVariantEditor();
}
};
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
RulesVariant rulesVariant = new RulesVariant("someRules", "someVariant");
this.tag.setValue(rulesVariant);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
assertEquals(rulesVariant, getPageContext().getAttribute("value"));
assertEquals(rulesVariant.toId(), getPageContext().getAttribute("displayValue"));
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
}
use of org.springframework.web.servlet.support.BindStatus in project spring-framework by spring-projects.
the class OptionTagTests method withNoLabel.
@Test
public void withNoLabel() throws Exception {
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");
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");
assertContainsAttribute(output, "class", "myClass");
assertContainsAttribute(output, "onclick", "CLICK");
assertBlockTagContains(output, "bar");
}
use of org.springframework.web.servlet.support.BindStatus in project spring-framework by spring-projects.
the class OptionTagTests method withCustomObjectAndEditorNotSelected.
@Test
public void withCustomObjectAndEditorNotSelected() throws Exception {
final PropertyEditor floatEditor = new SimpleFloatEditor();
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.35));
this.tag.setLabel("12.35f");
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);
assertAttributeNotPresent(output, "selected");
assertBlockTagContains(output, "12.35f");
}
use of org.springframework.web.servlet.support.BindStatus in project spring-framework by spring-projects.
the class OptionTagTests method withCustomObjectNotSelected.
@Test
public void withCustomObjectNotSelected() throws Exception {
String selectName = "testBean.someNumber";
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
this.tag.setValue(new Float(12.35));
this.tag.setLabel("GBP 12.35");
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", "12.35");
assertAttributeNotPresent(output, "selected");
assertBlockTagContains(output, "GBP 12.35");
}
Aggregations