Package org.springframework.beans.propertyeditors

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor


  public void testFieldSpecificCustomEditor() throws Exception {

    BeanWrapperFieldSetMapper<TestTwoDoubles> mapper = new BeanWrapperFieldSetMapper<TestTwoDoubles>() {
      @Override
      protected void initBinder(DataBinder binder) {
        binder.registerCustomEditor(Double.TYPE, "value", new CustomNumberEditor(Double.class, NumberFormat
            .getNumberInstance(Locale.GERMAN), true));
      }
    };
    mapper.setTargetType(TestTwoDoubles.class);
View Full Code Here


    BeanWrapperFieldSetMapper<TestTwoDoubles> mapper = new BeanWrapperFieldSetMapper<TestTwoDoubles>() {
      @Override
      public void registerCustomEditors(PropertyEditorRegistry registry) {
        super.registerCustomEditors(registry);
        registry.registerCustomEditor(Double.TYPE, "value", new CustomNumberEditor(Double.class, NumberFormat
            .getNumberInstance(Locale.GERMAN), true));
      }
    };
    mapper.setTargetType(TestTwoDoubles.class);
View Full Code Here

  @Test(expected = IllegalArgumentException.class)
  public void testSetCustomEditorsWithInvalidTypeName() throws Exception {

    DefaultPropertyEditorRegistrar mapper = new DefaultPropertyEditorRegistrar();
    mapper.setCustomEditors(Collections.singletonMap("FOO", new CustomNumberEditor(Long.class, true)));
  }
View Full Code Here

  @Test
  public void testSetCustomEditorsWithStringTypeName() throws Exception {

    DefaultPropertyEditorRegistrar mapper = new DefaultPropertyEditorRegistrar();
    mapper.setCustomEditors(Collections.singletonMap("java.lang.Long", new CustomNumberEditor(Long.class, true)));
    BeanWithIntArray result = new BeanWithIntArray();
    BeanWrapperImpl wrapper = new BeanWrapperImpl(result);
    mapper.registerCustomEditors(wrapper);
    wrapper.setPropertyValues(new MutablePropertyValues(Collections.singletonMap("number", "123")));
    assertEquals(123L, result.number);
View Full Code Here

  @Test(expected = IllegalArgumentException.class)
  public void testSetCustomEditorsWithInvalidType() throws Exception {

    DefaultPropertyEditorRegistrar mapper = new DefaultPropertyEditorRegistrar();
    mapper.setCustomEditors(Collections.singletonMap(new Object(), new CustomNumberEditor(Long.class, true)));
  }
View Full Code Here

     */
    @InitBinder
    protected void initBinder(HttpServletRequest request,
                              ServletRequestDataBinder binder) {
        binder.registerCustomEditor(Integer.class, null,
                                    new CustomNumberEditor(Integer.class, null, true));
        binder.registerCustomEditor(Long.class, null,
                                    new CustomNumberEditor(Long.class, null, true));
        binder.registerCustomEditor(byte[].class,
                                    new ByteArrayMultipartFileEditor());
        SimpleDateFormat dateFormat =
            new SimpleDateFormat(getText("date.format", request.getLocale()));
        dateFormat.setLenient(false);
View Full Code Here

  public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {

    NumberFormat nf = NumberFormat.getNumberInstance();

    // convert java.lang.Integer
    binder.registerCustomEditor(Integer.class, null, new CustomNumberEditor(
      Integer.class,
      nf,
      true));

    // convert java.util.Date
    SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
    dateFormat.setLenient(false);
    binder.registerCustomEditor(Date.class, null, new CustomDateEditor(dateFormat, true));

    // convert java.lang.Integer
    // Note: setting null in CustomNumberEditor means no format is
    // used in print an Integer (Otherwise, if NumberFormat is
    // used, a comma will be inserted in the number for Integer > 1000
    binder.registerCustomEditor(Integer.class, null, new CustomNumberEditor(
      Integer.class,
      null,
      true));

    // convert java.lang.Double
    binder.registerCustomEditor(Double.class, null, new CustomNumberEditor(
      Double.class,
      nf,
      true));

    // convert java.lang.Long
    binder.registerCustomEditor(Long.class, null, new CustomNumberEditor(Long.class, nf, true));

    // files
    binder.registerCustomEditor(byte[].class, null, new ByteArrayMultipartFileEditor());
  }
View Full Code Here

    // Spring's CustomBooleanEditor accepts more flag values than the JDK's default editor.
    editors.put(boolean.class, booleanEditor);
    editors.put(Boolean.class, booleanEditor);

    // The JDK does not contain default editors for number wrapper types!
    editors.put(Short.class, new CustomNumberEditor(Short.class, false));
    editors.put(Integer.class, new CustomNumberEditor(Integer.class, false));
    editors.put(Long.class, new CustomNumberEditor(Long.class, false));
    editors.put(BigInteger.class, new CustomNumberEditor(BigInteger.class, false));
    editors.put(Float.class, new CustomNumberEditor(Float.class, false));
    editors.put(Double.class, new CustomNumberEditor(Double.class, false));
    editors.put(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, false));

    editors.put(Collection.class, new CustomCollectionEditor(Collection.class));
    editors.put(Set.class, new CustomCollectionEditor(Set.class));
    editors.put(SortedSet.class, new CustomCollectionEditor(SortedSet.class));
    editors.put(List.class, new CustomCollectionEditor(List.class));
View Full Code Here

    // Spring's CustomBooleanEditor accepts more flag values than the JDK's default editor.
    editors.put(boolean.class, booleanEditor);
    editors.put(Boolean.class, booleanEditor);

    // The JDK does not contain default editors for number wrapper types!
    editors.put(Short.class, new CustomNumberEditor(Short.class, false));
    editors.put(Integer.class, new CustomNumberEditor(Integer.class, false));
    editors.put(Long.class, new CustomNumberEditor(Long.class, false));
    editors.put(BigInteger.class, new CustomNumberEditor(BigInteger.class, false));
    editors.put(Float.class, new CustomNumberEditor(Float.class, false));
    editors.put(Double.class, new CustomNumberEditor(Double.class, false));
    editors.put(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, false));

    editors.put(Collection.class, new CustomCollectionEditor(Collection.class));
    editors.put(Set.class, new CustomCollectionEditor(Set.class));
    editors.put(SortedSet.class, new CustomCollectionEditor(SortedSet.class));
    editors.put(List.class, new CustomCollectionEditor(List.class));
View Full Code Here

  private ProductValidator productValidator;
 
  @InitBinder
  public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(BigDecimal.class,
        new CustomNumberEditor(BigDecimal.class, true));
  }
View Full Code Here

TOP

Related Classes of org.springframework.beans.propertyeditors.CustomNumberEditor

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.