Search in sources :

Example 21 with BindStatus

use of org.springframework.web.servlet.support.BindStatus in project spring-framework by spring-projects.

the class InputTagTests method simpleBindTagWithinForm.

@Test
public void simpleBindTagWithinForm() throws Exception {
    BindTag bindTag = new BindTag();
    bindTag.setPath("name");
    bindTag.setPageContext(getPageContext());
    bindTag.doStartTag();
    BindStatus bindStatus = (BindStatus) getPageContext().findAttribute(BindTag.STATUS_VARIABLE_NAME);
    assertEquals("Rob", bindStatus.getValue());
}
Also used : BindTag(org.springframework.web.servlet.tags.BindTag) BindStatus(org.springframework.web.servlet.support.BindStatus) Test(org.junit.Test)

Example 22 with BindStatus

use of org.springframework.web.servlet.support.BindStatus in project spring-framework by spring-projects.

the class InputTagTests method withNestedBindTagWithinForm.

@Test
public void withNestedBindTagWithinForm() throws Exception {
    NestedPathTag nestedPathTag = new NestedPathTag();
    nestedPathTag.setPath("spouse.");
    nestedPathTag.setPageContext(getPageContext());
    nestedPathTag.doStartTag();
    BindTag bindTag = new BindTag();
    bindTag.setPath("name");
    bindTag.setPageContext(getPageContext());
    bindTag.doStartTag();
    BindStatus bindStatus = (BindStatus) getPageContext().findAttribute(BindTag.STATUS_VARIABLE_NAME);
    assertEquals("Sally", bindStatus.getValue());
}
Also used : NestedPathTag(org.springframework.web.servlet.tags.NestedPathTag) BindTag(org.springframework.web.servlet.tags.BindTag) BindStatus(org.springframework.web.servlet.support.BindStatus) Test(org.junit.Test)

Example 23 with BindStatus

use of org.springframework.web.servlet.support.BindStatus in project spring-framework by spring-projects.

the class OptionTagEnumTests method withJavaEnum.

@Test
@SuppressWarnings("rawtypes")
public void withJavaEnum() throws Exception {
    GenericBean testBean = new GenericBean();
    testBean.setCustomEnum(CustomEnum.VALUE_1);
    getPageContext().getRequest().setAttribute("testBean", testBean);
    String selectName = "testBean.customEnum";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue("VALUE_1");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);
    String output = getWriter().toString();
    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "VALUE_1");
    assertContainsAttribute(output, "selected", "selected");
}
Also used : GenericBean(org.springframework.tests.sample.beans.GenericBean) BindStatus(org.springframework.web.servlet.support.BindStatus) Test(org.junit.Test)

Example 24 with BindStatus

use of org.springframework.web.servlet.support.BindStatus in project spring-framework by spring-projects.

the class OptionTagTests method withPropertyEditor.

@Test
public void withPropertyEditor() throws Exception {
    String selectName = "testBean.stringArray";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {

        @Override
        public PropertyEditor getEditor() {
            return new StringArrayPropertyEditor();
        }
    };
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
    this.tag.setValue(ARRAY_SOURCE);
    this.tag.setLabel("someArray");
    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", ARRAY_SOURCE);
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, "someArray");
}
Also used : StringArrayPropertyEditor(org.springframework.beans.propertyeditors.StringArrayPropertyEditor) BindStatus(org.springframework.web.servlet.support.BindStatus) Test(org.junit.Test)

Example 25 with BindStatus

use of org.springframework.web.servlet.support.BindStatus in project spring-framework by spring-projects.

the class OptionTagTests method asBodyTagSelected.

@Test
public void asBodyTagSelected() 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("Rob Harrop");
    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);
    assertBlockTagContains(output, bodyContent);
}
Also used : MockBodyContent(org.springframework.mock.web.test.MockBodyContent) BindStatus(org.springframework.web.servlet.support.BindStatus) Test(org.junit.Test)

Aggregations

BindStatus (org.springframework.web.servlet.support.BindStatus)47 Test (org.junit.Test)44 TestBean (org.springframework.tests.sample.beans.TestBean)22 PageContext (javax.servlet.jsp.PageContext)19 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)19 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)18 Errors (org.springframework.validation.Errors)14 ServletRequestDataBinder (org.springframework.web.bind.ServletRequestDataBinder)14 PropertyEditor (java.beans.PropertyEditor)4 StringReader (java.io.StringReader)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Document (org.dom4j.Document)4 Element (org.dom4j.Element)4 SAXReader (org.dom4j.io.SAXReader)4 StringArrayPropertyEditor (org.springframework.beans.propertyeditors.StringArrayPropertyEditor)4 MockBodyContent (org.springframework.mock.web.test.MockBodyContent)3 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)2 BindTag (org.springframework.web.servlet.tags.BindTag)2 SimpleHash (freemarker.template.SimpleHash)1