@InitBinder("systemNotificationForm") protected void initBinder(WebDataBinder binder) { binder.setValidator(systemNotificationValidator); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm"); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true)); binder.registerCustomEditor( SystemNotificationType.class, new EnumEditor(SystemNotificationType.class)); binder.registerCustomEditor( SystemNotificationSeverity.class, new EnumEditor(SystemNotificationSeverity.class)); binder.registerCustomEditor( List.class, "types", new CustomCollectionEditor(List.class) { @Override protected Object convertElement(Object element) { SystemNotificationType type = null; if (element != null) { try { type = SystemNotificationType.valueOf((String) element); } catch (Exception ex) { log.error( String.format( "Error converting element to SystemNotificationType: %s", element), ex); } } return type; } }); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(SignatureForm.class, new EnumPropertyEditor(SignatureForm.class)); binder.registerCustomEditor( SignaturePackaging.class, new EnumPropertyEditor(SignaturePackaging.class)); binder.registerCustomEditor(SignatureLevel.class, new EnumPropertyEditor(SignatureLevel.class)); }
// http://baggioback.iteye.com/blog/1753469 @InitBinder protected void dataBinder(WebDataBinder webDataBinder) { // 一个用于修剪(trim)String类型的属性编辑器,具有将一个空字符串转化为null值的选项。 // 默认没有注册,必须由用户在需要的时候自行注册 webDataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); webDataBinder.registerCustomEditor(Date.class, new DateEditor(true)); }
/** 初始化数据绑定 1. 将所有传递进来的String进行HTML编码,防止XSS攻击 2. 将字段中Date类型转换为String类型 */ @InitBinder protected void initBinder( WebDataBinder binder, HttpServletRequest request, HttpServletResponse response) { this.request = request; this.response = response; // 将所有传递进来的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() : ""; } }); binder.registerCustomEditor( Date.class, new PropertyEditorSupport() { @Override public void setAsText(String text) { setValue(DateUtils.parseDate(text)); } }); }
@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH); // dd/MM/yyyy CustomDateEditor editor = new CustomDateEditor(dateFormat, true); binder.registerCustomEditor(Date.class, editor); binder.registerCustomEditor(Family.class, familyEditor); }
/** * Method which will be used for populating command and form object arguments. * * @param binder Binder for data binding from web request parameters to JavaBean objects. */ @InitBinder protected void initBinder(WebDataBinder binder) { SimpleDateFormat dobFormat = new SimpleDateFormat("MM/dd/yyyy"); binder.registerCustomEditor(Date.class, "dateOfBirth", new CustomDateEditor(dobFormat, true)); binder.registerCustomEditor(Date.class, "startDate", new CustomDateEditor(dobFormat, true)); binder.registerCustomEditor(Date.class, "endDate", new CustomDateEditor(dobFormat, true)); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.setDisallowedFields(new String[] {"studentMobile"}); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy****mm****dd"); binder.registerCustomEditor(Date.class, "studentDOB", new CustomDateEditor(dateFormat, false)); binder.registerCustomEditor(String.class, "studentName", new StudentNameEditor()); }
/** Register custom, context-specific property editors */ @InitBinder public void initBinder( WebDataBinder binder, HttpServletRequest request) { // Register static property editors. binder.registerCustomEditor( java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor()); binder.registerCustomEditor( byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor()); binder.registerCustomEditor( boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false)); binder.registerCustomEditor( Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true)); binder.registerCustomEditor( java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor( java.math.BigDecimal.class, true)); binder.registerCustomEditor( Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true)); binder.registerCustomEditor( java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor()); binder.registerCustomEditor( String.class, new org.skyway.spring.util.databinding.StringEditor()); binder.registerCustomEditor( Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true)); binder.registerCustomEditor( Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true)); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor( Long.class, null, new CustomNumberEditor(Long.class, NumberFormat.getNumberInstance(), true)); binder.registerCustomEditor(Boolean.class, null, new CustomBooleanEditor(true)); }
@Override @InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(Driver.class, new AbstractModelEditor(Driver.class)); binder.registerCustomEditor(FuelCard.class, new AbstractModelEditor(FuelCard.class)); binder.registerCustomEditor(FuelVendor.class, new AbstractModelEditor(FuelVendor.class)); binder.registerCustomEditor(Long.TYPE, new CustomNumberEditor(Long.class, false)); }
@Override public void initBinder(WebDataBinder binder, WebRequest request) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); binder.registerCustomEditor(String.class, new StringTrimmerEditor(false)); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(MediaType.class, new MediaTypeEditor(MediaType.class)); binder.registerCustomEditor( String.class, new StringTrimmerEditor( true)); /* Converts empty strings into null when a form is submitted */ }
@Override @InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); binder.registerCustomEditor(Long.TYPE, new CustomNumberEditor(Long.class, false)); binder.registerCustomEditor(Location.class, new AbstractModelEditor(Location.class)); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.setValidator(formValidator); binder.registerCustomEditor(Date.class, "dateAdded", datePropertyEditor); binder.registerCustomEditor(Date.class, "dateLastModified", datePropertyEditor); binder.registerCustomEditor(State.class, "state", statePropertyEditor); binder.registerCustomEditor(Country.class, "country", countryPropertyEditor); binder.registerCustomEditor(City.class, "city", cityPropertyEditor); }
@InitBinder public void initBinder(WebDataBinder dataBinder) { dataBinder.registerCustomEditor(Category.class, new CategoryPropertyEditor()); dataBinder.registerCustomEditor(null, "descriptionList", new DescriptionPropertyEditor()); dataBinder.registerCustomEditor(null, "question.answer", new AnswerPropertyEditor()); dataBinder.registerCustomEditor( null, "skipRule", new SkipPatternPropertyEditor<FormElementSkipRule>(FormElementSkipRule.class, skipDao)); }
@Override public void initBinder(WebDataBinder binder, WebRequest request) { // 注册自定义的属性编辑器 // 1、日期 DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); CustomDateEditor dateEditor = new CustomDateEditor(df, true); // 表示如果命令对象有Date类型的属性,将使用该属性编辑器进行类型转换 binder.registerCustomEditor(Date.class, dateEditor); // 自定义的电话号码编辑器 binder.registerCustomEditor(PhoneNumberModel.class, new PhoneNumberModelEditor()); }
@InitBinder public void initBinder(WebDataBinder binder) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(true); dateFormat2.setLenient(true); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); binder.registerCustomEditor(Date.class, "spacedate", new CustomDateEditor(dateFormat2, true)); binder.registerCustomEditor( Date.class, "spacedateReality", new CustomDateEditor(dateFormat2, true)); binder.registerCustomEditor( Date.class, "spacedate_begin", new CustomDateEditor(dateFormat2, true)); binder.registerCustomEditor( Date.class, "spacedate_end", new CustomDateEditor(dateFormat2, true)); }
@SuppressWarnings("unused") @InitBinder({"myCommand", "date"}) private void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }
@InitBinder public void dataBinding(WebDataBinder binder) { binder.addValidators(feriasValidation); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, "dataInicio", new CustomDateEditor(dateFormat, true)); }
@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); }
@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); sdf.setLenient(true); binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true)); }
@InitBinder public void initBinder(WebDataBinder binder, @PathVariable("hotel") String hotel) { assertEquals("Invalid path variable value", "42", hotel); binder.initBeanPropertyAccess(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }
@InitBinder protected void initBinder(WebDataBinder binder) throws Exception { binder.registerCustomEditor( List.class, "document.developmentProposal.propScienceKeywords", new PropScienceKeywordEditor()); binder.registerCustomEditor( List.class, "document.developmentProposal.propSpecialReviews.specialReviewExemptions", new PropSpecialReviewExemptionTypeEditor()); // For add line binding binder.registerCustomEditor( List.class, "newCollectionLines.specialReviewExemptions", new PropSpecialReviewExemptionTypeEditor()); }
@InitBinder protected void initBinder(WebDataBinder binder) { if (binder.getTarget() instanceof User) { binder.setValidator(registerValidator); SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); } }
@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat sdf = new SimpleDateFormat("mm-dd-yyyy"); sdf.setLenient(true); binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true)); binder.registerCustomEditor( long.class, new PropertyEditorSupport() { @Override public void setAsText(String text) { if (text.trim().length() == 0) { text = "0"; } long ch = Long.parseLong(text); setValue(ch); } }); }
@InitBinder private void dateBinder(WebDataBinder binder) { // The date format to parse or output your dates SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); // Create a new CustomDateEditor CustomDateEditor editor = new CustomDateEditor(dateFormat, true); // Register it as custom editor for the Date type binder.registerCustomEditor(Date.class, editor); }
@InitBinder public void initBinder(WebDataBinder binder) { // 날짜 데이타가 값이 입력이 안되는 경우 '' 를 Date 변환시 에러가 나는 문제 처리. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); dateFormat.setLenient(false); // true passed to CustomDateEditor constructor means convert empty String to null binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); }
public void initBinder(WebDataBinder binder, WebRequest request) { SimpleDateFormat dateFormat = new SimpleDateFormat(formatStr); dateFormat.setLenient(false); binder.registerCustomEditor( Date.class, new CustomDateEditor(dateFormat, true)); // true表示允许时间字段为空 // binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));//将空字符串转换成null // binder.registerCustomEditor(int.class, new MyCustomNumberEditor(Integer.class, // true));//当不能获取到基本类型的时候,就是用bea中的默认值 // binder.registerCustomEditor(long.class, new MyCustomNumberEditor(Long.class, false)); // binder.registerCustomEditor(boolean.class, new CustomBooleanEditor(true)); // binder.registerCustomEditor(Menu.class, new MenuEditor()); }
@InitBinder("announcement") public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat(customDateFormat); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); binder.registerCustomEditor(Topic.class, topicEditor); binder.setAllowedFields( new String[] { "id", "created", "author", "title", "abstractText", "message", "link", "startDisplay", "endDisplay", "parent", "action", "attachments" }); }
@InitBinder protected void initBinder(WebDataBinder binder) { binder.registerCustomEditor( Access.class, new PropertyEditorSupport() { public void setAsText(String value) { System.out.println("init"); Integer accessId = Integer.parseInt(value); Access access = accessService.getAccess(accessId); setValue(access); } }); }