use of org.springframework.web.servlet.support.BindStatus in project spring-framework by spring-projects.
the class BindTagTests method bindTagWithoutErrors.
@Test
public void bindTagWithoutErrors() throws JspException {
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
BindTag tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb");
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertTrue("Has status variable", status != null);
assertTrue("Correct expression", status.getExpression() == null);
assertTrue("Correct value", status.getValue() == null);
assertTrue("Correct displayValue", "".equals(status.getDisplayValue()));
assertTrue("Correct isError", !status.isError());
assertTrue("Correct errorCodes", status.getErrorCodes().length == 0);
assertTrue("Correct errorMessages", status.getErrorMessages().length == 0);
assertTrue("Correct errorCode", "".equals(status.getErrorCode()));
assertTrue("Correct errorMessage", "".equals(status.getErrorMessage()));
assertTrue("Correct errorMessagesAsString", "".equals(status.getErrorMessagesAsString(",")));
}
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");
}
Aggregations