Package org.springframework.validation

Examples of org.springframework.validation.DataBinder


    protected Object createAttributeFromRequestValue(String sourceValue,
                                                     String attributeName,
                                                     MethodParameter parameter,
                                                     WebDataBinderFactory binderFactory,
                                                     NativeWebRequest request) throws Exception {
        DataBinder binder = binderFactory.createBinder(request, null, attributeName);
        ConversionService conversionService = binder.getConversionService();
        if (conversionService != null) {
            TypeDescriptor source = TypeDescriptor.valueOf(String.class);
            TypeDescriptor target = new TypeDescriptor(parameter);
            if (conversionService.canConvert(source, target)) {
                return binder.convertIfNecessary(sourceValue, parameter.getParameterType(), parameter);
            }
        }
        return null;
    }
View Full Code Here


    DefaultConversionService.addDefaultConverters(conversionService);
    registrar.registerFormatters(conversionService);

    SimpleDateBean bean = new SimpleDateBean();
    bean.getChildren().add(new SimpleDateBean());
    binder = new DataBinder(bean);
    binder.setConversionService(conversionService);

    LocaleContextHolder.setLocale(Locale.US);
  }
View Full Code Here

      }
    });
    conversionService.addFormatterForFieldType(Number.class, new NumberFormatter());
    conversionService.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());
    LocaleContextHolder.setLocale(Locale.US);
    binder = new DataBinder(new TestBean());
    binder.setConversionService(conversionService);
  }
View Full Code Here

   */
  protected Object createAttributeFromRequestValue(String sourceValue, String attributeName,
      MethodParameter parameter, WebDataBinderFactory binderFactory, NativeWebRequest request)
      throws Exception {

    DataBinder binder = binderFactory.createBinder(request, null, attributeName);
    ConversionService conversionService = binder.getConversionService();
    if (conversionService != null) {
      TypeDescriptor source = TypeDescriptor.valueOf(String.class);
      TypeDescriptor target = new TypeDescriptor(parameter);
      if (conversionService.canConvert(source, target)) {
        return binder.convertIfNecessary(sourceValue, parameter.getParameterType(), parameter);
      }
    }
    return null;
  }
View Full Code Here

  @Override
  public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
      NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

    DataBinder dataBinder = binderFactory.createBinder(webRequest, null, null);
    ModelMap redirectAttributes  = new RedirectAttributesModelMap(dataBinder);
    mavContainer.setRedirectModel(redirectAttributes);
    return redirectAttributes;
  }
View Full Code Here

  }

  public void testBindTagWithIndexedPropertiesAndCustomEditor() throws JspException {
    PageContext pc = createPageContext();
    IndexedTestBean tb = new IndexedTestBean();
    DataBinder binder = new ServletRequestDataBinder(tb, "tb");
    binder.registerCustomEditor(TestBean.class, null, new PropertyEditorSupport() {
      @Override
      public String getAsText() {
        return "something";
      }
    });
    Errors errors = binder.getBindingResult();
    errors.rejectValue("array[0]", "code1", "message1");
    errors.rejectValue("array[0]", "code2", "message2");
    pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);

    BindTag tag = new BindTag();
View Full Code Here

    registrar.registerFormatters(conversionService);

    JodaTimeBean bean = new JodaTimeBean();
    bean.getChildren().add(new JodaTimeBean());
    binder = new DataBinder(bean);
    binder.setConversionService(conversionService);

    LocaleContextHolder.setLocale(Locale.US);
    JodaTimeContext context = new JodaTimeContext();
    context.setTimeZone(DateTimeZone.forID("-05:00"));
View Full Code Here

    assertEquals("Sat, 12 Aug 1995 13:30:00 GMT", binder.getBindingResult().getFieldValue("date"));
  }

  @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());
  }
View Full Code Here

  private FormattingConversionService conversionService;

  @Before
  public void setup() {
    this.conversionService = new DefaultFormattingConversionService();
    DataBinder dataBinder = new DataBinder(null);
    dataBinder.setConversionService(conversionService);

    this.redirectAttributes = new RedirectAttributesModelMap(dataBinder);
  }
View Full Code Here

    registrar.registerFormatters(conversionService);

    DateTimeBean bean = new DateTimeBean();
    bean.getChildren().add(new DateTimeBean());
    binder = new DataBinder(bean);
    binder.setConversionService(conversionService);

    LocaleContextHolder.setLocale(Locale.US);
    DateTimeContext context = new DateTimeContext();
    context.setTimeZone(ZoneId.of("-05:00"));
View Full Code Here

TOP

Related Classes of org.springframework.validation.DataBinder

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.