Example usage for org.springframework.web.servlet.support BindStatus BindStatus

List of usage examples for org.springframework.web.servlet.support BindStatus BindStatus

Introduction

In this page you can find the example usage for org.springframework.web.servlet.support BindStatus BindStatus.

Prototype

public BindStatus(RequestContext requestContext, String path, boolean htmlEscape) throws IllegalStateException 

Source Link

Document

Create a new BindStatus instance, representing a field or object status.

Usage

From source file:org.hdiv.web.servlet.tags.form.OptionsTagTests.java

public void testWithItemsNullReference() throws Exception {
    getPageContext().getRequest().removeAttribute("countries");
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE,
            new BindStatus(getRequestContext(), "testBean.country", false));

    this.tag.setItems("${countries}");
    this.tag.setItemValue("isoCode");
    this.tag.setItemLabel("name");
    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);
    String output = getWriter().toString();
    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());
}

From source file:org.hdiv.web.servlet.tags.form.OptionTagTests.java

public void testWithEnum() throws Exception {
    getPageContext().setAttribute(SelectTagHDIV.LIST_VALUE_PAGE_ATTRIBUTE,
            new BindStatus(getRequestContext(), "testBean.favouriteColour", false));

    String value = Colour.GREEN.getCode().toString();
    String label = Colour.GREEN.getLabel();

    this.tag.setValue(value);
    this.tag.setLabel(label);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();/*w w  w .jav  a2 s .  c om*/

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);

    String hdivValue = this.confidentiality ? "0" : value;
    assertContainsAttribute(output, "value", hdivValue);
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, label);
}

From source file:org.hdiv.web.servlet.tags.form.OptionsTagTests.java

public void testWithoutItems() throws Exception {
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE,
            new BindStatus(getRequestContext(), "testBean.country", false));

    this.tag.setItemValue("isoCode");
    this.tag.setItemLabel("name");
    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);
    String output = getOutput();/*from  www  . j a  v a  2  s. com*/
    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());
}

From source file:org.hdiv.web.servlet.tags.form.OptionTagTests.java

public void testWithEnumNotSelected() throws Exception {
    getPageContext().setAttribute(SelectTagHDIV.LIST_VALUE_PAGE_ATTRIBUTE,
            new BindStatus(getRequestContext(), "testBean.favouriteColour", false));

    String value = Colour.BLUE.getCode().toString();
    String label = Colour.BLUE.getLabel();

    this.tag.setValue(value);
    this.tag.setLabel(label);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();//from  w  w  w.jav a 2 s  .c om

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);

    String hdivValue = this.confidentiality ? "0" : value;
    assertContainsAttribute(output, "value", hdivValue);
    assertAttributeNotPresent(output, "selected");
    assertBlockTagContains(output, label);
}

From source file:org.hdiv.web.servlet.tags.form.OptionTagTests.java

public void testWithPropertyEditor() throws Exception {
    BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.stringArray", false) {
        public PropertyEditor getEditor() {
            return new StringArrayPropertyEditor();
        }/*w ww . j a v a 2s.c o m*/
    };
    getPageContext().setAttribute(SelectTagHDIV.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);

    String hdivValue = this.confidentiality ? "0" : ARRAY_SOURCE;
    assertContainsAttribute(output, "value", hdivValue);
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, "someArray");

}

From source file:org.hdiv.web.servlet.tags.form.OptionTagTests.java

public void testWithPropertyEditorStringComparison() throws Exception {
    final PropertyEditor testBeanEditor = new TestBeanPropertyEditor();
    testBeanEditor.setValue(new TestBean("Sally"));
    BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.spouse", false) {
        public PropertyEditor getEditor() {
            return testBeanEditor;
        }//from   w w w .j  ava2  s.  c om
    };
    getPageContext().setAttribute(SelectTagHDIV.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);

    String hdivValue = this.confidentiality ? "0" : "Sally";
    assertContainsAttribute(output, "value", hdivValue);
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, "Sally");
}

From source file:org.hdiv.web.servlet.tags.form.OptionTagTests.java

public void testWithCustomObjectSelected() throws Exception {
    getPageContext().setAttribute(SelectTagHDIV.LIST_VALUE_PAGE_ATTRIBUTE,
            new BindStatus(getRequestContext(), "testBean.someNumber", false));
    this.tag.setValue("${myNumber}");
    this.tag.setLabel("GBP ${myNumber}");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();/*from ww w .ja v a  2  s  .c  o  m*/

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);

    String hdivValue = this.confidentiality ? "0" : "12.34";
    assertContainsAttribute(output, "value", hdivValue);
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, "GBP 12.34");
}

From source file:org.hdiv.web.servlet.tags.form.OptionTagTests.java

public void testWithCustomObjectNotSelected() throws Exception {
    getPageContext().setAttribute(SelectTagHDIV.LIST_VALUE_PAGE_ATTRIBUTE,
            new BindStatus(getRequestContext(), "testBean.someNumber", false));
    this.tag.setValue("${myOtherNumber}");
    this.tag.setLabel("GBP ${myOtherNumber}");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();/*w ww . ja v a 2  s . c  om*/

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);

    String hdivValue = this.confidentiality ? "0" : "12.35";
    assertContainsAttribute(output, "value", hdivValue);
    assertAttributeNotPresent(output, "selected");
    assertBlockTagContains(output, "GBP 12.35");
}

From source file:org.hdiv.web.servlet.tags.form.OptionTagTests.java

public void testWithCustomObjectAndEditorSelected() throws Exception {
    final PropertyEditor floatEditor = new SimpleFloatEditor();
    floatEditor.setValue(new Float("12.34"));
    BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.someNumber", false) {
        public PropertyEditor getEditor() {
            return floatEditor;
        }//from  www . j  av a2s  .c  om
    };
    getPageContext().setAttribute(SelectTagHDIV.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    this.tag.setValue("${myNumber}");
    this.tag.setLabel("${myNumber}");

    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");
}

From source file:org.hdiv.web.servlet.tags.form.OptionTagTests.java

public void testWithCustomObjectAndEditorNotSelected() throws Exception {
    final PropertyEditor floatEditor = new SimpleFloatEditor();
    BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.someNumber", false) {
        public PropertyEditor getEditor() {
            return floatEditor;
        }//from w  ww .  j  av  a  2  s . c  o m
    };
    getPageContext().setAttribute(SelectTagHDIV.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    this.tag.setValue("${myOtherNumber}");
    this.tag.setLabel("${myOtherNumber}");

    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");
}