Examples of CustomNumberEditor


Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

    assertEquals("7", gb.getLongMap().get(new Long("6")));
  }

  public void testGenericMapWithCollectionValueFactoryMethod() throws MalformedURLException {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    bf.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
    RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
    rbd.setFactoryMethodName("createInstance");

    Map input = new HashMap();
    HashSet value1 = new HashSet();
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

    public static class MyRegistrar implements PropertyEditorRegistrar {
        private final static String[] NUMBERS = { "zero", "one", "two", "three", "four", "five", "six", "seven",
                "eight", "nine", "ten" };

        public void registerCustomEditors(PropertyEditorRegistry registry) {
            PropertyEditor editor = new CustomNumberEditor(Long.class, true) {
                @Override
                public void setAsText(String text) {
                    for (int i = 0; i < NUMBERS.length; i++) {
                        if (NUMBERS[i].equalsIgnoreCase(text)) {
                            setValue(i);
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

  throws ServletException {
    SystemUtils.print("initBinder");
    // to actually be able to convert Multipart instance to byte[]
    // we have to register a custom editor
    binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
    binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, DecimalFormat.getInstance(RequestContextUtils.getLocale(request)),true));
    binder.registerCustomEditor(GregorianCalendar.class,new GregorianCalendarPropertyEditor());
    binder.registerCustomEditor( Double.class, new CustomNumberEditor(Double.class, DecimalFormat.getInstance(RequestContextUtils.getLocale(request)),true));
//    binder.registerCustomEditor(File.class, new FileEditor());
//    binder.registerCustomEditor( Float.class, new CustomNumberEditor(Float.class, DecimalFormat.getInstance(RequestContextUtils.getLocale(request)),true));
    // now Spring knows how to handle multipart object and convert them
  }
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

 
  public void initBinder(WebDataBinder binder, WebRequest request) {       
    /*Necessary to run into GAE.*/
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
    binder.registerCustomEditor(Boolean.class, new CustomBooleanEditor("true", "false", true));
    binder.registerCustomEditor(Long.class, null, new CustomNumberEditor(Long.class, null, true));
        binder.registerCustomEditor(Integer.class, null, new CustomNumberEditor(Integer.class, null, true));
        binder.registerCustomEditor(Float.class, null, new CustomNumberEditor(Float.class, null, true));
        binder.registerCustomEditor(Set.class, "tags", new TagCollectionEditor(Set.class, true));
        binder.registerCustomEditor(List.class, new CustomCollectionEditor(List.class, true));
        binder.registerCustomEditor(Text.class, new CustomTextEditor());
        binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true));
        binder.registerCustomEditor(GeoPt.class, new CustomGeoPointsEditor());
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

   */
  public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {

    NumberFormat nf = NumberFormat.getNumberInstance();
    // convert java.lang.Long
    binder.registerCustomEditor(Long.class, null, new CustomNumberEditor(Long.class, nf, true));
  }
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

     * 初始化binder的回调函数.
     *
     * @see MultiActionController#createBinder(HttpServletRequest,Object)
     */
    protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {
      binder.registerCustomEditor(Short.class, new CustomNumberEditor(Short.class, true));
        binder.registerCustomEditor(Integer.class, new CustomNumberEditor(Integer.class, true));
        binder.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, true));
        binder.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, true));
        binder.registerCustomEditor(Double.class, new CustomNumberEditor(Double.class, true));
        binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, true));
        binder.registerCustomEditor(BigInteger.class, new CustomNumberEditor(BigInteger.class, true));
       
        binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
       
    }
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

  private BankService bankService;

  @InitBinder
  public void initBinder(WebDataBinder binder) {
    // accept "," as a decimal separator
    binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, true) {
      @Override
      public void setAsText(String text) throws IllegalArgumentException {
        super.setAsText(StringUtils.replaceChars(text, ',', '.'));
      }
    });
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

    this.defaultEditors.put(boolean.class, new CustomBooleanEditor(false));
    this.defaultEditors.put(Boolean.class, new CustomBooleanEditor(true));

    // The JDK does not contain default editors for number wrapper types!
    // Override JDK primitive number editors with our own CustomNumberEditor.
    this.defaultEditors.put(byte.class, new CustomNumberEditor(Byte.class, false));
    this.defaultEditors.put(Byte.class, new CustomNumberEditor(Byte.class, true));
    this.defaultEditors.put(short.class, new CustomNumberEditor(Short.class, false));
    this.defaultEditors.put(Short.class, new CustomNumberEditor(Short.class, true));
    this.defaultEditors.put(int.class, new CustomNumberEditor(Integer.class, false));
    this.defaultEditors.put(Integer.class, new CustomNumberEditor(Integer.class, true));
    this.defaultEditors.put(long.class, new CustomNumberEditor(Long.class, false));
    this.defaultEditors.put(Long.class, new CustomNumberEditor(Long.class, true));
    this.defaultEditors.put(float.class, new CustomNumberEditor(Float.class, false));
    this.defaultEditors.put(Float.class, new CustomNumberEditor(Float.class, true));
    this.defaultEditors.put(double.class, new CustomNumberEditor(Double.class, false));
    this.defaultEditors.put(Double.class, new CustomNumberEditor(Double.class, true));
    this.defaultEditors.put(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, true));
    this.defaultEditors.put(BigInteger.class, new CustomNumberEditor(BigInteger.class, true));

    // Only register config value editors if explicitly requested.
    if (this.configValueEditorsActive) {
      StringArrayPropertyEditor sae = new StringArrayPropertyEditor();
      this.defaultEditors.put(String[].class, sae);
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

      bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 125);

    bw.registerCustomEditor(int.class, "array.somePath", new CustomNumberEditor(Integer.class, false));
    sw.start("array3");
    for (int i = 0; i < 1000; i++) {
      bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

    bw.registerCustomEditor(int.class, "array[0].somePath", new CustomNumberEditor(Integer.class, false));
    sw.start("array3");
    for (int i = 0; i < 1000; i++) {
      bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

    bw.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, false));
    sw.start("array4");
    for (int i = 0; i < 100; i++) {
      bw.setPropertyValue("array", input);
    }
    sw.stop();
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

  @Test
  public void testGenericLowerBoundedSet() {
    GenericBean<?> gb = new GenericBean<Object>();
    BeanWrapper bw = new BeanWrapperImpl(gb);
    bw.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, true));
    Set<String> input = new HashSet<String>();
    input.add("4");
    input.add("5");
    bw.setPropertyValue("numberSet", input);
    assertTrue(gb.getNumberSet().contains(new Integer(4)));
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.