SelectTagTests.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:spring4-understanding 作者:
@Test
public void withListAndEditor() throws Exception {
    this.tag.setPath("realCountry");
    this.tag.setItems(Country.getCountries());
    this.tag.setItemValue("isoCode");
    this.tag.setItemLabel("name");
    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();
    String output = getOutput();
    assertTrue(output.startsWith("<select "));
    assertTrue(output.endsWith("</select>"));
    assertTrue(output.contains("option value=\"AT\" selected=\"selected\">Austria"));
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号