List of usage examples for org.springframework.validation BeanPropertyBindingResult getPropertyAccessor
@Override public final ConfigurablePropertyAccessor getPropertyAccessor()
From source file:org.hdiv.web.servlet.tags.form.HiddenInputTagTests.java
public void testWithCustomBinder() throws Exception { this.tag.setPath("myFloat"); BeanPropertyBindingResult errors = new BeanPropertyBindingResult(this.bean, COMMAND_NAME); errors.getPropertyAccessor().registerCustomEditor(Float.class, new SimpleFloatEditor()); exposeBindingResult(errors);//from w w w .j a v a 2 s .c o m assertEquals(Tag.SKIP_BODY, this.tag.doStartTag()); String output = getWriter().toString(); assertTagOpened(output); assertTagClosed(output); assertContainsAttribute(output, "type", "hidden"); String value = this.confidentiality ? "0" : "12.34f"; assertContainsAttribute(output, "value", value); }
From source file:org.hdiv.web.servlet.tags.form.TextareaTagTests.java
public void testCustomBind() throws Exception { BeanPropertyBindingResult result = new BeanPropertyBindingResult(createTestBean(), "testBean"); result.getPropertyAccessor().registerCustomEditor(Float.class, new SimpleFloatEditor()); exposeBindingResult(result);/*from w w w . j av a2s .c o m*/ this.tag.setPath("myFloat"); assertEquals(Tag.SKIP_BODY, this.tag.doStartTag()); String output = getWriter().toString(); assertContainsAttribute(output, "name", "myFloat"); assertBlockTagContains(output, "12.34f"); }
From source file:org.hdiv.web.servlet.tags.form.OptionsTagTests.java
public void testWithCollectionAndCustomEditor() throws Exception { PropertyEditor propertyEditor = new SimpleFloatEditor(); TestBean target = new TestBean(); target.setMyFloat(new Float("12.34")); BeanPropertyBindingResult errors = new BeanPropertyBindingResult(target, COMMAND_NAME); errors.getPropertyAccessor().registerCustomEditor(Float.class, propertyEditor); exposeBindingResult(errors);/* w ww . ja v a 2s . c om*/ getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.myFloat", false)); this.tag.setItems("${floats}"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); 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", 6, children.size()); Element element = (Element) rootElement.selectSingleNode("option[text() = '12.34f']"); assertNotNull("Option node should not be null", element); assertEquals("12.34 node not selected", "selected", element.attribute("selected").getValue()); assertNull("No id rendered", element.attribute("id")); element = (Element) rootElement.selectSingleNode("option[text() = '12.35f']"); assertNotNull("Option node should not be null", element); assertNull("12.35 node incorrectly selected", element.attribute("selected")); assertNull("No id rendered", element.attribute("id")); }
From source file:org.hdiv.web.servlet.tags.form.InputTagTests.java
public void testWithCustomBinder() throws Exception { this.tag.setPath("myFloat"); BeanPropertyBindingResult errors = new BeanPropertyBindingResult(this.rob, COMMAND_NAME); errors.getPropertyAccessor().registerCustomEditor(Float.class, new SimpleFloatEditor()); exposeBindingResult(errors);/* w w w . j a va 2 s .c o m*/ assertEquals(Tag.SKIP_BODY, this.tag.doStartTag()); String output = getWriter().toString(); assertTagOpened(output); assertTagClosed(output); assertContainsAttribute(output, "type", getType()); assertValueAttribute(output, "12.34f"); }
From source file:org.hdiv.web.servlet.tags.form.SelectTagTests.java
public void testWithFloatCustom() throws Exception { PropertyEditor propertyEditor = new SimpleFloatEditor(); BeanPropertyBindingResult errors = new BeanPropertyBindingResult(getTestBean(), COMMAND_NAME); errors.getPropertyAccessor().registerCustomEditor(Float.class, propertyEditor); exposeBindingResult(errors);//www .j a v a 2 s .c om this.tag.setPath("myFloat"); Float[] array = new Float[] { new Float("12.30"), new Float("12.32"), new Float("12.34"), new Float("12.36"), new Float("12.38"), new Float("12.40"), new Float("12.42"), new Float("12.44"), new Float("12.46"), new Float("12.48") }; this.tag.setItems(array); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getWriter().toString(); assertTrue(output.startsWith("<select ")); assertTrue(output.endsWith("</select>")); SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals("select", rootElement.getName()); assertEquals("myFloat", rootElement.attribute("name").getValue()); List children = rootElement.elements(); assertEquals("Incorrect number of children", array.length, children.size()); Element e = (Element) rootElement.selectSingleNode("option[text() = '12.34f']"); assertEquals("'12.34' node not selected", "selected", e.attribute("selected").getValue()); e = (Element) rootElement.selectSingleNode("option[text() = '12.32f']"); assertNull("'12.32' node incorrectly selected", e.attribute("selected")); }
From source file:org.hdiv.web.servlet.tags.form.OptionTagTests.java
public void testMultiBind() throws Exception { BeanPropertyBindingResult result = new BeanPropertyBindingResult(new TestBean(), "testBean"); result.getPropertyAccessor().registerCustomEditor(TestBean.class, "friends", new FriendEditor()); exposeBindingResult(result);//w w w .ja v a 2 s .c o m BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.friends", false); getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus); this.tag.setValue(new TestBean("foo")); this.tag.doStartTag(); this.tag.doEndTag(); }