Search in sources :

Example 36 with InitBinder

use of org.springframework.web.bind.annotation.InitBinder in project spring-cloud by Rogge666.

the class BaseController method initBinder.

@InitBinder
protected void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    dateFormat.setLenient(false);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
Also used : CustomDateEditor(org.springframework.beans.propertyeditors.CustomDateEditor) SimpleDateFormat(java.text.SimpleDateFormat) InitBinder(org.springframework.web.bind.annotation.InitBinder)

Example 37 with InitBinder

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

the class AdminBasicEntityController method initBinder.

// *********************************
// ADDITIONAL SPRING-BOUND METHODS *
// *********************************
/**
 * Invoked on every request to provide the ability to register specific binders for Spring's binding process.
 * By default, we register a binder that treats empty Strings as null and a Boolean editor that supports either true
 * or false. If the value is passed in as null, it will treat it as false.
 *
 * @param binder
 */
@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
    binder.registerCustomEditor(Boolean.class, new NonNullBooleanEditor());
}
Also used : NonNullBooleanEditor(org.broadleafcommerce.openadmin.web.editor.NonNullBooleanEditor) StringTrimmerEditor(org.springframework.beans.propertyeditors.StringTrimmerEditor) InitBinder(org.springframework.web.bind.annotation.InitBinder)

Example 38 with InitBinder

use of org.springframework.web.bind.annotation.InitBinder in project spring-framework by spring-projects.

the class InitBinderDataBinderFactory method isBinderMethodApplicable.

/**
 * Determine whether the given {@code @InitBinder} method should be used
 * to initialize the given {@link WebDataBinder} instance. By default we
 * check the specified attribute names in the annotation value, if any.
 */
protected boolean isBinderMethodApplicable(HandlerMethod initBinderMethod, WebDataBinder dataBinder) {
    InitBinder ann = initBinderMethod.getMethodAnnotation(InitBinder.class);
    Assert.state(ann != null, "No InitBinder annotation");
    String[] names = ann.value();
    return (ObjectUtils.isEmpty(names) || ObjectUtils.containsElement(names, dataBinder.getObjectName()));
}
Also used : InitBinder(org.springframework.web.bind.annotation.InitBinder)

Example 39 with InitBinder

use of org.springframework.web.bind.annotation.InitBinder in project disconf by knightliao.

the class BaseController method dateBinder.

/**
 * 绑定时间
 *
 * @param binder
 */
@InitBinder
protected void dateBinder(WebDataBinder binder) {
    // The date format to parse or output your dates
    SimpleDateFormat dateFormat = new SimpleDateFormat(WebConstants.TIME_FORMAT);
    // Create a new CustomDateEditor
    CustomDateEditor editor = new CustomDateEditor(dateFormat, true);
    // Register it as custom editor for the Date type
    binder.registerCustomEditor(Date.class, editor);
}
Also used : CustomDateEditor(org.springframework.beans.propertyeditors.CustomDateEditor) SimpleDateFormat(java.text.SimpleDateFormat) InitBinder(org.springframework.web.bind.annotation.InitBinder)

Aggregations

InitBinder (org.springframework.web.bind.annotation.InitBinder)39 SimpleDateFormat (java.text.SimpleDateFormat)14 CustomDateEditor (org.springframework.beans.propertyeditors.CustomDateEditor)14 ByteArrayMultipartFileEditor (org.springframework.web.multipart.support.ByteArrayMultipartFileEditor)10 DateFormat (java.text.DateFormat)7 StringTrimmerEditor (org.springframework.beans.propertyeditors.StringTrimmerEditor)4 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 EcLogAnnotation (com.easy.cloud.core.common.log.annotation.EcLogAnnotation)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 CustomLocalDateEditor (org.apache.dubbo.admin.controller.editors.CustomLocalDateEditor)1 CustomLocalDateTimeEditor (org.apache.dubbo.admin.controller.editors.CustomLocalDateTimeEditor)1 NonNullBooleanEditor (org.broadleafcommerce.openadmin.web.editor.NonNullBooleanEditor)1 FlowEncapsulationType (org.openkilda.model.FlowEncapsulationType)1