Example usage for java.beans PropertyEditorSupport PropertyEditorSupport

List of usage examples for java.beans PropertyEditorSupport PropertyEditorSupport

Introduction

In this page you can find the example usage for java.beans PropertyEditorSupport PropertyEditorSupport.

Prototype

public PropertyEditorSupport() 

Source Link

Document

Constructs a PropertyEditorSupport object.

Usage

From source file:ua.epam.rd.web.AbstractPizzaContoller.java

@InitBinder
private void pizzaBinder(WebDataBinder binder) {
    binder.registerCustomEditor(Pizza.class, new PropertyEditorSupport() {
        @Override//  w w w  . ja v a2 s.  co m
        public void setAsText(String pizzaId) {
            Pizza pizza = null;
            if (pizzaId != null && !pizzaId.trim().isEmpty()) {
                Long id = Long.valueOf(pizzaId);
                pizza = getPizzaById(id);
            }
            setValue(pizza);
        }
    });
}

From source file:com.firevo.product.ProductController.java

@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(ProductColorType.class, new PropertyEditorSupport() {
        @Override//w ww .  j  a  va2  s .  com
        public void setAsText(String text) throws IllegalArgumentException {
            setValue(ProductColorType.find(Integer.valueOf(text)));
        }
    });

    binder.registerCustomEditor(ProductShopType.class, new PropertyEditorSupport() {
        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            setValue(ProductShopType.find(Integer.valueOf(text)));
        }
    });

    binder.registerCustomEditor(LocalDate.class, new PropertyEditorSupport() {
        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            try {
                String[] split = text.split(",");
                setValue(LocalDate.of(Integer.valueOf(split[0]), Integer.valueOf(split[1]),
                        Integer.valueOf(split[2])));
            } catch (Exception ex) {
                setValue(null);
            }
        }
    });
}

From source file:app.web.AbstractController.java

@InitBinder
public void initBinder(WebDataBinder binder) {
    //IMPORTANT/*w ww.ja v a2 s  . c  o  m*/
    binder.initDirectFieldAccess();
    binder.registerCustomEditor(PersistentObject.class, new PropertyEditorSupport() {
        @Override
        public void setAsText(String s) throws IllegalArgumentException {
            setValue(Db.get(ID.parse(s)));
        }

        @Override
        public String getAsText() {
            return getValue() != null ? ((PersistentObject) getValue()).getId().toString() : null;
        }
    });
    binder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
        @Override
        public void setAsText(String s) throws IllegalArgumentException {
            try {
                setValue(DATE_FORMAT.parse(s));
            } catch (ParseException e) {
                throw new IllegalArgumentException(e);
            }
        }

        @Override
        public String getAsText() {
            return getValue() != null ? DATE_FORMAT.format(getValue()) : null;
        }
    });
}

From source file:com.yunmel.syncretic.core.BaseController.java

@InitBinder
public void initBinder(WebDataBinder binder) {
    // String??StringHTML?XSS
    binder.registerCustomEditor(String.class, new PropertyEditorSupport() {
        @Override//from  w w  w .j  a v a  2  s .c om
        public void setAsText(String text) {
            setValue(text == null ? null : StringEscapeUtils.escapeHtml4(text.trim()));
        }

        @Override
        public String getAsText() {
            Object value = getValue();
            return value != null ? value.toString() : "";
        }
    });
    // Date ?
    binder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
        @Override
        public void setAsText(String text) {
            try {
                setValue(DateUtils.parseDate(text, "yyyy-MM-dd HH:mm:ss"));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

    });
    // Timestamp ?
    binder.registerCustomEditor(Timestamp.class, new PropertyEditorSupport() {
        @Override
        public void setAsText(String text) {
            Date date = null;
            try {
                date = DateUtils.parseDate(text, "yyyy-MM-dd HH:mm:ss");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            setValue(date == null ? null : new Timestamp(date.getTime()));
        }
    });

}

From source file:com.opencart.controller.AdminController.java

@InitBinder
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    binder.registerCustomEditor(Category.class, "category", new PropertyEditorSupport() {
        @Override/*from   w w w.ja v  a 2 s. com*/
        public void setAsText(String text) {
            if (!text.isEmpty()) {
                Category category = (Category) categoryService.get(Integer.parseInt(text));
                setValue(category);
            }
        }
    });
}

From source file:com.opencart.controller.ProductController.java

@InitBinder
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    binder.registerCustomEditor(SubCategory.class, "subCategory", new PropertyEditorSupport() {
        @Override/* w w  w .  j  a  v  a 2s.c om*/
        public void setAsText(String text) {
            if (!text.isEmpty()) {
                SubCategory subCategory = (SubCategory) subCategoryService.getById(Integer.parseInt(text));
                setValue(subCategory);
            }
        }
    });
}

From source file:com.amuponda.estorehack.client.web.controller.ProductController.java

@InitBinder
public void initBinder(WebDataBinder webDataBinder) {
    webDataBinder.registerCustomEditor(Category.class, new PropertyEditorSupport() {
        @Override/*from  w ww .j  a  v a 2s.  com*/
        public void setAsText(String text) {
            setValue(categoryService.findByName(text));
        }
    });
}

From source file:com.github.ibole.infrastructure.web.spring.GlobalBindingHandler.java

/**
 * ??./*from w  w  w .j a v a  2s.c om*/
 *  1. ?StringHTML?XSS 
 *  2. Date?String
 *  @param binder WebDataBinder
 */
@InitBinder
protected void initBinder(WebDataBinder binder) {
    // String??StringHTML?XSS
    binder.registerCustomEditor(String.class, new PropertyEditorSupport() {
        @Override
        public void setAsText(String text) {
            setValue(text == null ? null : StringEscapeUtils.escapeHtml4(text.trim()));
        }

        @Override
        public String getAsText() {
            Object value = getValue();
            return value != null ? value.toString() : "";
        }
    });
    // Date ?
    binder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
        @Override
        public void setAsText(String text) {
            setValue(DateUtils.parseDate(text));
        }
        // @Override
        // public String getAsText() {
        // Object value = getValue();
        // return value != null ? DateUtils.formatDateTime((Date)value) : "";
        // }
    });
}

From source file:org.eclipse.virgo.samples.formtags.par.web.FormController.java

protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    binder.registerCustomEditor(Country.class, new CountryEditor(this.userManager));
    binder.registerCustomEditor(Colour.class, new PropertyEditorSupport() {
        public void setAsText(String string) throws IllegalArgumentException {
            Integer code = new Integer(string);
            setValue(Colour.getColour(code));
        }/*  w  ww .ja  va  2s .co  m*/
    });
}

From source file:com.yzsl.web.CommonController.java

/**
 * ??/*w  w  w .  j a v  a2  s  . co  m*/
 * 1. ?StringHTML?XSS
 * 2. Date?String
 */
@InitBinder
protected void initBinder(WebDataBinder binder) {
    // String??StringHTML?XSS
    binder.registerCustomEditor(String.class, new PropertyEditorSupport() {
        @Override
        public void setAsText(String text) {
            setValue(text == null ? null : text.trim());
            //            setValue(text == null ? null : StringEscapeUtils.escapeHtml4(text.trim()));
        }

        @Override
        public String getAsText() {
            Object value = getValue();
            return value != null ? value.toString() : "";
        }
    });
    // Date ?
    binder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
        @Override
        public void setAsText(String text) {
            try {

                setValue(DateUtils.parseDate(text, "MM-dd-yyyy", "MM/dd/yyyy", "yyyy-MM-dd", "yyyy/MM/dd"));
                logger.debug("---" + getValue());
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
}