Search in sources :

Example 1 with TransformTag

use of org.springframework.web.servlet.tags.TransformTag in project spring-framework by spring-projects.

the class SelectTagTests method withListAndTransformTag.

@Test
public void withListAndTransformTag() throws Exception {
    this.tag.setPath("country");
    this.tag.setItems(Country.getCountries());
    assertList(true);
    TransformTag transformTag = new TransformTag();
    transformTag.setValue(Country.getCountries().get(0));
    transformTag.setVar("key");
    transformTag.setParent(this.tag);
    transformTag.setPageContext(getPageContext());
    transformTag.doStartTag();
    assertEquals("Austria(AT)", getPageContext().findAttribute("key"));
}
Also used : TransformTag(org.springframework.web.servlet.tags.TransformTag) Test(org.junit.Test)

Example 2 with TransformTag

use of org.springframework.web.servlet.tags.TransformTag in project spring-framework by spring-projects.

the class SelectTagTests method withListAndTransformTagAndEditor.

@Test
public void withListAndTransformTagAndEditor() throws Exception {
    this.tag.setPath("realCountry");
    this.tag.setItems(Country.getCountries());
    BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(getTestBean(), "testBean");
    bindingResult.getPropertyAccessor().registerCustomEditor(Country.class, new PropertyEditorSupport() {

        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            setValue(Country.getCountryWithIsoCode(text));
        }

        @Override
        public String getAsText() {
            return ((Country) getValue()).getName();
        }
    });
    getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "testBean", bindingResult);
    this.tag.doStartTag();
    TransformTag transformTag = new TransformTag();
    transformTag.setValue(Country.getCountries().get(0));
    transformTag.setVar("key");
    transformTag.setParent(this.tag);
    transformTag.setPageContext(getPageContext());
    transformTag.doStartTag();
    assertEquals("Austria", getPageContext().findAttribute("key"));
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) TransformTag(org.springframework.web.servlet.tags.TransformTag) PropertyEditorSupport(java.beans.PropertyEditorSupport) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 TransformTag (org.springframework.web.servlet.tags.TransformTag)2 PropertyEditorSupport (java.beans.PropertyEditorSupport)1 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)1