Package org.springframework.validation

Examples of org.springframework.validation.BeanPropertyBindingResult


  }

  public void testWithMultiValueWithEditor() throws Exception {
    this.tag.setPath("stringArray");
    this.tag.setValue("   foo");
    BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
    MyStringTrimmerEditor editor = new MyStringTrimmerEditor();
    bindingResult.getPropertyEditorRegistry().registerCustomEditor(String.class, editor);
    getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult);

    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);
    assertEquals(1, editor.count);
View Full Code Here


  }

  public void testWithMultiValueIntegerWithEditor() throws Exception {
    this.tag.setPath("someIntegerArray");
    this.tag.setValue("   1");
    BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
    MyIntegerEditor editor = new MyIntegerEditor();
    bindingResult.getPropertyEditorRegistry().registerCustomEditor(Integer.class, editor);
    getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult);

    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);
    assertEquals(1, editor.count);
View Full Code Here

  public void testCollectionOfPetsWithEditor() throws Exception {
    this.tag.setPath("pets");
    this.tag.setValue(new ItemPet("Rudiger"));

    BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
    PropertyEditorSupport editor = new ItemPet.CustomEditor();
    bindingResult.getPropertyEditorRegistry().registerCustomEditor(ItemPet.class, editor);
    getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult);

    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);
View Full Code Here

    assertContainsAttribute(output, "name", "name");
    assertBlockTagContains(output, HTML_ESCAPED_NAME);
  }

  public void testCustomBind() throws Exception {
    BeanPropertyBindingResult result = new BeanPropertyBindingResult(createTestBean(), "testBean");
    result.getPropertyAccessor().registerCustomEditor(Float.class, new SimpleFloatEditor());
    exposeBindingResult(result);
    this.tag.setPath("myFloat");
    assertEquals(Tag.SKIP_BODY, this.tag.doStartTag());
    String output = getOutput();
    assertContainsAttribute(output, "name", "myFloat");
View Full Code Here

  public void testWithErrors() throws Exception {
    this.tag.setPath("name");
    this.tag.setCssClass("good");
    this.tag.setCssErrorClass("bad");

    BeanPropertyBindingResult errors = new BeanPropertyBindingResult(this.rob, COMMAND_NAME);
    errors.rejectValue("name", "some.code", "Default Message");
    errors.rejectValue("name", "too.short", "Too Short");
    exposeBindingResult(errors);

    assertEquals(Tag.SKIP_BODY, this.tag.doStartTag());

    String output = getOutput();
View Full Code Here

  }

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

    assertEquals(Tag.SKIP_BODY, this.tag.doStartTag());

    String output = getOutput();
View Full Code Here

    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);
  }

  public void testMultiBind() throws Exception {
    BeanPropertyBindingResult result = new BeanPropertyBindingResult(new TestBean(), "testBean");
    result.getPropertyAccessor().registerCustomEditor(TestBean.class, "friends", new FriendEditor());
    exposeBindingResult(result);

    BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.friends", false);

    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
View Full Code Here

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

    getPageContext().setAttribute(
        SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.myFloat", false));
View Full Code Here

    @Test
    public void updateWidget_valid() {
        Widget widget = new Widget(123L, "http://example.com/widget");
        widget.setTitle("Widget title");
        widget.setType("OpenSocial");
        BindingResult errors = new BeanPropertyBindingResult(widget, "widget");
        SessionStatus sessionStatus = createMock(SessionStatus.class);

        service.updateWidget(widget);
        sessionStatus.setComplete();
        expectLastCall();
        replay(service, sessionStatus);
        String view = controller.updateWidgetDetail(widget, errors, validToken, validToken, sessionStatus);
        verify(service, sessionStatus);

        assertFalse("No errors", errors.hasErrors());
        assertEquals("redirect:123", view);

    }
View Full Code Here

    }

    @Test(expected = SecurityException.class)
    public void updateWidget_wrongToken() {
        Widget widget = new Widget();
        BindingResult errors = new BeanPropertyBindingResult(widget, "widget");
        SessionStatus sessionStatus = createMock(SessionStatus.class);

        sessionStatus.setComplete();
        expectLastCall();
        replay(sessionStatus);
View Full Code Here

TOP

Related Classes of org.springframework.validation.BeanPropertyBindingResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.