Search in sources :

Example 11 with InitBinder

use of org.springframework.web.bind.annotation.InitBinder in project spring-hibernate by WeInnovate.

the class StudentController method anyMethod.

@InitBinder
public void anyMethod(WebDataBinder webDataBinder) {
    StringTrimmerEditor ste = new StringTrimmerEditor(true);
    webDataBinder.registerCustomEditor(String.class, ste);
}
Also used : StringTrimmerEditor(org.springframework.beans.propertyeditors.StringTrimmerEditor) InitBinder(org.springframework.web.bind.annotation.InitBinder)

Example 12 with InitBinder

use of org.springframework.web.bind.annotation.InitBinder in project Gemma by PavlidisLab.

the class BaseFormController method initBinder.

/**
 * Set up a custom property editor for converting form inputs to real objects. Override this to add additional
 * custom editors (call super.initBinder() in your implementation)
 */
@InitBinder
protected void initBinder(WebDataBinder binder) {
    NumberFormat nf = NumberFormat.getNumberInstance();
    binder.registerCustomEditor(Integer.class, null, new CustomNumberEditor(Integer.class, nf, true));
    binder.registerCustomEditor(Long.class, null, new CustomNumberEditor(Long.class, nf, true));
    binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
}
Also used : CustomNumberEditor(org.springframework.beans.propertyeditors.CustomNumberEditor) NumberFormat(java.text.NumberFormat) ByteArrayMultipartFileEditor(org.springframework.web.multipart.support.ByteArrayMultipartFileEditor) InitBinder(org.springframework.web.bind.annotation.InitBinder)

Example 13 with InitBinder

use of org.springframework.web.bind.annotation.InitBinder in project wechat by dllwh.

the class BaseController method initBinder.

/**
 * ----------------------------------------------------- Fields end
 */
/**
 * @方法:将前台传递过来的日期格式的字符串,自动转化为Date类型
 * @创建人:独泪了无痕
 * @param binder
 */
@InitBinder
public void initBinder(ServletRequestDataBinder binder) {
    // String类型转换,将所有传递进来的String进行HTML编码,防止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 DateConvertEditor());
}
Also used : DateConvertEditor(com.cdeledu.core.interceptors.DateConvertEditor) PropertyEditorSupport(java.beans.PropertyEditorSupport) InitBinder(org.springframework.web.bind.annotation.InitBinder)

Example 14 with InitBinder

use of org.springframework.web.bind.annotation.InitBinder in project spring-data-document-examples by spring-projects.

the class RestaurantController method registerConverters.

@InitBinder
void registerConverters(WebDataBinder binder) {
    if (binder.getConversionService() instanceof GenericConversionService) {
        GenericConversionService conversionService = (GenericConversionService) binder.getConversionService();
        conversionService.addConverter(getRestaurantConverter());
    }
}
Also used : GenericConversionService(org.springframework.core.convert.support.GenericConversionService) InitBinder(org.springframework.web.bind.annotation.InitBinder)

Example 15 with InitBinder

use of org.springframework.web.bind.annotation.InitBinder in project spring-data-document-examples by spring-projects.

the class SignUpController method registerConverters.

@InitBinder
void registerConverters(WebDataBinder binder) {
    if (binder.getConversionService() instanceof GenericConversionService) {
        GenericConversionService conversionService = (GenericConversionService) binder.getConversionService();
        conversionService.addConverter(getRestaurantConverter());
        conversionService.addConverter(getUserAccountConverter());
        conversionService.addConverter(getRestaurantConverterFromString());
    }
}
Also used : GenericConversionService(org.springframework.core.convert.support.GenericConversionService) InitBinder(org.springframework.web.bind.annotation.InitBinder)

Aggregations

InitBinder (org.springframework.web.bind.annotation.InitBinder)35 SimpleDateFormat (java.text.SimpleDateFormat)13 CustomDateEditor (org.springframework.beans.propertyeditors.CustomDateEditor)13 ByteArrayMultipartFileEditor (org.springframework.web.multipart.support.ByteArrayMultipartFileEditor)9 DateFormat (java.text.DateFormat)6 StringTrimmerEditor (org.springframework.beans.propertyeditors.StringTrimmerEditor)3 GenericConversionService (org.springframework.core.convert.support.GenericConversionService)3 PropertyEditorSupport (java.beans.PropertyEditorSupport)2 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)2 DateTimeFormatterBuilder (org.joda.time.format.DateTimeFormatterBuilder)2 DateConvertEditor (com.cdeledu.core.interceptors.DateConvertEditor)1 TodoPriorityPropertyEditor (com.in28minutes.springmvc.web.util.TodoPriorityPropertyEditor)1 DateTimePropertyEditorSupport (hry.core.util.springmvcPropertyeditor.DateTimePropertyEditorSupport)1 StringPropertyEditorSupport (hry.core.util.springmvcPropertyeditor.StringPropertyEditorSupport)1 NumberFormat (java.text.NumberFormat)1 NonNullBooleanEditor (org.broadleafcommerce.openadmin.web.editor.NonNullBooleanEditor)1 CustomNumberEditor (org.springframework.beans.propertyeditors.CustomNumberEditor)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 DefinitionTypeConverter (org.talend.components.service.rest.DefinitionTypeConverter)1 ConnectorTypologyConverter (org.talend.components.service.rest.dto.ConnectorTypologyConverter)1