Package org.springframework.validation

Examples of org.springframework.validation.DataBinder.bind()


      }
    };
    binder.initDirectFieldAccess();
    PropertyEditorUtil.registerUimaFITEditors(binder);
    binder.setRequiredFields(mandatoryValues.toArray(new String[mandatoryValues.size()]));
    binder.bind(values);
    if (binder.getBindingResult().hasErrors()) {
      StringBuilder sb = new StringBuilder();
      sb.append("Errors initializing [" + component.getClass() + "]");
      for (ObjectError error : binder.getBindingResult().getAllErrors()) {
        if (sb.length() > 0) {
View Full Code Here


  @Test
  public void testBindDateWithoutErrorFallingBackToDateConstructor() {
    DataBinder binder = new DataBinder(new JodaTimeBean());
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("date", "Sat, 12 Aug 1995 13:30:00 GMT");
    binder.bind(propertyValues);
    assertEquals(0, binder.getBindingResult().getErrorCount());
  }

  @Test
  public void testBindDateAnnotated() {
View Full Code Here

    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("customTypeValue", "custom");
    pvs.addPropertyValue("dateValue", S01_12_2009);
    pvs.addPropertyValue("integerValue", "123");
    pvs.addPropertyValue("stringValue", "string");
    dataBinder.bind(pvs);

    assertThat(target.getIntegerValue(), is(equalTo(new Integer(123))));
    assertThat(target.getStringValue(), is(equalTo("string")));
    assertThat(target.getDateValue(), is(equalTo(D01_12_2009)));
    assertThat(target.getCustomTypeValue(), is(equalTo(new CustomType("custom"))));
View Full Code Here

    dataBinder.setIgnoreUnknownFields(false);
    dataBinder.setConversionService(conversionService);
    MutablePropertySources mps = new MutablePropertySources();
    mps.addFirst(new MapPropertySource("options", (Map) raw));
    try {
      dataBinder.bind(new PropertySourcesPropertyValues(mps));
    }
    catch (InvalidPropertyException e) {
      dataBinder.getBindingResult().addError(new FieldError("options", e.getPropertyName(), e.getMessage()));
    }
View Full Code Here

   */
    @Override
  public T mapFieldSet(FieldSet fs) throws BindException {
    T copy = getBean();
    DataBinder binder = createBinder(copy);
    binder.bind(new MutablePropertyValues(getBeanProperties(copy, fs.getProperties())));
    if (binder.getBindingResult().hasErrors()) {
      throw new BindException(binder.getBindingResult());
    }
    return copy;
  }
View Full Code Here

  @Test
  public void testPlaceholdersBinding() {
    TestBean target = new TestBean();
    DataBinder binder = new DataBinder(target);
    binder.bind(new PropertySourcesPropertyValues(this.propertySources));
    assertEquals("bar", target.getName());
  }

  @Test
  public void testPlaceholdersBindingNonEnumerable() {
View Full Code Here

  @Test
  public void testPlaceholdersBindingNonEnumerable() {
    FooBean target = new FooBean();
    DataBinder binder = new DataBinder(target);
    binder.bind(new PropertySourcesPropertyValues(this.propertySources,
        (Collection<String>) null, Collections.singleton("foo")));
    assertEquals("bar", target.getFoo());
  }

  @Test
View Full Code Here

  public void testPlaceholdersBindingWithError() {
    TestBean target = new TestBean();
    DataBinder binder = new DataBinder(target);
    this.propertySources.addFirst(new MapPropertySource("another", Collections
        .<String, Object> singletonMap("something", "${nonexistent}")));
    binder.bind(new PropertySourcesPropertyValues(this.propertySources));
    assertEquals("bar", target.getName());
  }

  @Test
  public void testPlaceholdersErrorInNonEnumerable() {
View Full Code Here

      @Override
      public Object getProperty(String name) {
        return new Object();
      }
    });
    binder.bind(new PropertySourcesPropertyValues(this.propertySources,
        (Collection<String>) null, Collections.singleton("name")));
    assertEquals(null, target.getName());
  }

  public static class TestBean {
View Full Code Here

      }
    };
    binder.initDirectFieldAccess();
    PropertyEditorUtil.registerUimaFITEditors(binder);
    binder.setRequiredFields(mandatoryValues.toArray(new String[mandatoryValues.size()]));
    binder.bind(values);
    if (binder.getBindingResult().hasErrors()) {
      StringBuilder sb = new StringBuilder();
      sb.append("Errors initializing [" + component.getClass() + "]");
      for (ObjectError error : binder.getBindingResult().getAllErrors()) {
        if (sb.length() > 0) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.