Package org.springframework.format.number

Examples of org.springframework.format.number.NumberFormatter


  public void testBindingWithFormatter() {
    TestBean tb = new TestBean();
    DataBinder binder = new DataBinder(tb);
    FormattingConversionService conversionService = new FormattingConversionService();
    DefaultConversionService.addDefaultConverters(conversionService);
    conversionService.addFormatterForFieldType(Float.class, new NumberFormatter());
    binder.setConversionService(conversionService);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("myFloat", "1,2");

    LocaleContextHolder.setLocale(Locale.GERMAN);
View Full Code Here


  public void testBindingErrorWithFormatter() {
    TestBean tb = new TestBean();
    DataBinder binder = new DataBinder(tb);
    FormattingConversionService conversionService = new FormattingConversionService();
    DefaultConversionService.addDefaultConverters(conversionService);
    conversionService.addFormatterForFieldType(Float.class, new NumberFormatter());
    binder.setConversionService(conversionService);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("myFloat", "1x2");

    LocaleContextHolder.setLocale(Locale.GERMAN);
View Full Code Here

  public void testBindingWithFormatterAgainstList() {
    BeanWithIntegerList tb = new BeanWithIntegerList();
    DataBinder binder = new DataBinder(tb);
    FormattingConversionService conversionService = new FormattingConversionService();
    DefaultConversionService.addDefaultConverters(conversionService);
    conversionService.addFormatterForFieldType(Float.class, new NumberFormatter());
    binder.setConversionService(conversionService);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("integerList[0]", "1");

    LocaleContextHolder.setLocale(Locale.GERMAN);
View Full Code Here

  public void testBindingErrorWithFormatterAgainstList() {
    BeanWithIntegerList tb = new BeanWithIntegerList();
    DataBinder binder = new DataBinder(tb);
    FormattingConversionService conversionService = new FormattingConversionService();
    DefaultConversionService.addDefaultConverters(conversionService);
    conversionService.addFormatterForFieldType(Float.class, new NumberFormatter());
    binder.setConversionService(conversionService);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("integerList[0]", "1x2");

    LocaleContextHolder.setLocale(Locale.GERMAN);
View Full Code Here

  public void testBindingWithFormatterAgainstFields() {
    TestBean tb = new TestBean();
    DataBinder binder = new DataBinder(tb);
    FormattingConversionService conversionService = new FormattingConversionService();
    DefaultConversionService.addDefaultConverters(conversionService);
    conversionService.addFormatterForFieldType(Float.class, new NumberFormatter());
    binder.setConversionService(conversionService);
    binder.initDirectFieldAccess();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("myFloat", "1,2");
View Full Code Here

    TestBean tb = new TestBean();
    DataBinder binder = new DataBinder(tb);
    binder.initDirectFieldAccess();
    FormattingConversionService conversionService = new FormattingConversionService();
    DefaultConversionService.addDefaultConverters(conversionService);
    conversionService.addFormatterForFieldType(Float.class, new NumberFormatter());
    binder.setConversionService(conversionService);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("myFloat", "1x2");

    LocaleContextHolder.setLocale(Locale.GERMAN);
View Full Code Here

    LocaleContextHolder.setLocale(null);
  }

  @Test
  public void testFormatFieldForTypeWithFormatter() throws ParseException {
    formattingService.addFormatterForFieldType(Number.class, new NumberFormatter());
    String formatted = formattingService.convert(3, String.class);
    assertEquals("3", formatted);
    Integer i = formattingService.convert("3", Integer.class);
    assertEquals(new Integer(3), i);
  }
View Full Code Here

    }
  }

  @Test
  public void testPrintNull() throws ParseException {
    formattingService.addFormatterForFieldType(Number.class, new NumberFormatter());
    assertEquals("", formattingService.convert(null, TypeDescriptor.valueOf(Integer.class), TypeDescriptor.valueOf(String.class)));
  }
View Full Code Here

    assertEquals("", formattingService.convert(null, TypeDescriptor.valueOf(Integer.class), TypeDescriptor.valueOf(String.class)));
  }

  @Test
  public void testParseNull() throws ParseException {
    formattingService.addFormatterForFieldType(Number.class, new NumberFormatter());
    assertNull(formattingService
        .convert(null, TypeDescriptor.valueOf(String.class), TypeDescriptor.valueOf(Integer.class)));
  }
View Full Code Here

        .convert(null, TypeDescriptor.valueOf(String.class), TypeDescriptor.valueOf(Integer.class)));
  }

  @Test
  public void testParseEmptyString() throws ParseException {
    formattingService.addFormatterForFieldType(Number.class, new NumberFormatter());
    assertNull(formattingService.convert("", TypeDescriptor.valueOf(String.class), TypeDescriptor.valueOf(Integer.class)));
  }
View Full Code Here

TOP

Related Classes of org.springframework.format.number.NumberFormatter

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.