@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor( byte[].class, new ByteArrayMultipartFileEditor()); binder.registerCustomEditor( Date.class, new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true)); binder.registerCustomEditor( Long.class, new CustomNumberEditor(Long.class, true)); binder.registerCustomEditor( Double.class, new CustomNumberEditor(Double.class, true)); binder.registerCustomEditor( BigDecimal.class, new CustomNumberEditor( BigDecimal.class, new DecimalFormat("#,##0.00"), true)); binder.registerCustomEditor( Boolean.class, new CustomBooleanEditor(false)); }
/** * Set up a custom property editor for converting form inputs to real * objects * * @param request * the current request * @param binder * the data binder */ @InitBinder protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) { binder.registerCustomEditor(Integer.class, null, new CustomNumberEditor(Integer.class, null, true)); binder.registerCustomEditor(Long.class, null, new CustomNumberEditor( Long.class, null, true)); binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); log.trace(request.getLocale()); log.trace(getText("date.format", request.getLocale())); SimpleDateFormat dateFormat = new SimpleDateFormat(getText( "date.format", request.getLocale())); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, null, new CustomDateEditor( dateFormat, true)); }
/** * Set up a custom property editor for converting form inputs to real * objects. * * @param request the current request * @param binder the data binder */ @InitBinder protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) { binder.registerCustomEditor(Integer.class, null, new CustomNumberEditor(Integer.class, null, true)); binder.registerCustomEditor(Long.class, null, new CustomNumberEditor( Long.class, null, true)); binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd G 'at' HH:mm:ss z"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, null, new CustomDateEditor( dateFormat, true)); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor( byte[].class, new ByteArrayMultipartFileEditor()); binder.registerCustomEditor( Date.class, new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true)); binder.registerCustomEditor( Long.class, new CustomNumberEditor(Long.class, true)); binder.registerCustomEditor( Double.class, new CustomNumberEditor(Double.class, true)); binder.registerCustomEditor( BigDecimal.class, new CustomNumberEditor( BigDecimal.class, new DecimalFormat("#,##0.00"), true)); binder.registerCustomEditor( Boolean.class, new CustomBooleanEditor(false)); binder.registerCustomEditor( Object.class, new ObjectTypeEditorHelper()); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor( byte[].class, new ByteArrayMultipartFileEditor()); binder.registerCustomEditor( Date.class, new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true)); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor( ExpedientTipus.class, new ExpedientTipusTypeEditor(dissenyService)); binder.registerCustomEditor( byte[].class, new ByteArrayMultipartFileEditor()); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor( byte[].class, new ByteArrayMultipartFileEditor()); binder.registerCustomEditor( DefinicioProces.class, new DefinicioProcesTypeEditor(dissenyService)); binder.registerCustomEditor( Camp.class, new CampTypeEditor(dissenyService)); }
/** * {@inheritDoc} */ @Override protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws ServletException { if (initBinderRequired) { // to actually be able to convert Multipart instance to byte[] // we have to register a custom editor binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); // now Spring knows how to handle multipart object and convert them } }
/** * {@inheritDoc} */ @Override protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws ServletException { // to actually be able to convert Multipart instance to byte[] // we have to register a custom editor binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); // now Spring knows how to handle multipart object and convert them }
@Override protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws ServletException { // to actually be able to convert Multipart instance to byte[] // we have to register a custom editor binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); // now Spring knows how to handle multipart object and convert them }
@InitBinder protected void initBinder(PortletRequestDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy", Locale.US); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); binder.setAllowedFields(new String[] {"author","title","description","availability","count","website","coverPng"}); }
/** * Utility method for creating a GrailsDataBinder instance * * @param target The target object to bind to * @param objectName The name of the object * @return A GrailsDataBinder instance */ public static GrailsDataBinder createBinder(Object target, String objectName) { GrailsDataBinder binder = new GrailsDataBinder(target, objectName); binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); binder.registerCustomEditor(String.class, new StringMultipartFileEditor()); binder.registerCustomEditor(Currency.class, new CurrencyEditor()); binder.registerCustomEditor(Locale.class, new LocaleEditor()); binder.registerCustomEditor(TimeZone.class, new TimeZoneEditor()); binder.registerCustomEditor(URI.class, new UriEditor()); registerCustomEditors(binder); return binder; }
@Override public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { // Determine the necessary formats. NumberFormat nf = NumberFormat.getInstance(request.getLocale()); // Register the binders. binder.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, nf, true)); // to actually be able to convert Multipart instance to byte[] // we have to register a custom editor (in this case the // ByteArrayMultipartEditor binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); // now Spring knows how to handle multipart object and convert them }
@Override public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { // Determine the necessary formats. NumberFormat nf = NumberFormat.getInstance(request.getLocale()); // Register the binders. binder.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, nf, true)); binder.registerCustomEditor(Boolean.class, "propagateDelete", new CustomBooleanEditor(true)); // to actually be able to convert Multipart instance to byte[] // we have to register a custom editor (in this case the // ByteArrayMultipartEditor binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); // now Spring knows how to handle multipart object and convert them }
@InitBinder protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws ServletException { // Convert multipart object to byte[] binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); }
@Override public void initBinder(WebDataBinder binder, WebRequest request) { super.initBinder(binder, request); binder.registerCustomEditor(KualiDecimal.class, new UifCurrencyEditor()); binder.registerCustomEditor(KualiInteger.class, new UifKualiIntegerCurrencyEditor()); binder.registerCustomEditor(KualiPercent.class, new UifPercentageEditor()); binder.registerCustomEditor(java.sql.Date.class, new UifDateEditor()); binder.registerCustomEditor(java.util.Date.class, new UifDateEditor()); binder.registerCustomEditor(Timestamp.class, new UifTimestampEditor()); // TODO do we need this since we are switching to spring tags binder.registerCustomEditor(boolean.class, new UifBooleanEditor()); binder.registerCustomEditor(Boolean.class, new UifBooleanEditor()); binder.registerCustomEditor(Boolean.TYPE, new UifBooleanEditor()); // Use the spring custom number editor for Big decimals DecimalFormat bigIntFormatter = new DecimalFormat(); bigIntFormatter.setMaximumFractionDigits(340); binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, bigIntFormatter, true)); binder.registerCustomEditor(AbstractKualiDecimal.class, new CustomNumberEditor(AbstractKualiDecimal.class, bigIntFormatter, true)); // Use the spring StringTrimmerEditor editor for Strings binder.registerCustomEditor(String.class, new StringTrimmerEditor(false)); // Use the StringArrayPropertyEditor for string arrays with "," as the // separator binder.registerCustomEditor(String[].class, new StringArrayPropertyEditor(",", false)); binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); }
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws ServletException { // to actually be able to convert Multipart instance to byte[] // we have to register a custom editor binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); // now Spring knows how to handle multipart object and convert them }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor( byte[].class, new ByteArrayMultipartFileEditor()); }
@InitBinder protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws ServletException { binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); }
/** * Register the PropertyEditor for converting from a MultipartFile to an array of bytes. */ @InitBinder public void registerMultipartEditor(WebDataBinder binder) { binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); }
private void doTestBinding(MockCommonsMultipartResolver resolver, MockHttpServletRequest originalRequest, MultipartHttpServletRequest request) throws UnsupportedEncodingException { MultipartTestBean1 mtb1 = new MultipartTestBean1(); assertArrayEquals(null, mtb1.getField1()); assertEquals(null, mtb1.getField2()); ServletRequestDataBinder binder = new ServletRequestDataBinder(mtb1, "mybean"); binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); binder.bind(request); List<MultipartFile> file1List = request.getFiles("field1"); CommonsMultipartFile file1a = (CommonsMultipartFile) file1List.get(0); CommonsMultipartFile file1b = (CommonsMultipartFile) file1List.get(1); CommonsMultipartFile file2 = (CommonsMultipartFile) request.getFile("field2"); assertEquals(file1a, mtb1.getField1()[0]); assertEquals(file1b, mtb1.getField1()[1]); assertEquals(new String(file2.getBytes()), new String(mtb1.getField2())); MultipartTestBean2 mtb2 = new MultipartTestBean2(); assertArrayEquals(null, mtb2.getField1()); assertEquals(null, mtb2.getField2()); binder = new ServletRequestDataBinder(mtb2, "mybean"); binder.registerCustomEditor(String.class, "field1", new StringMultipartFileEditor()); binder.registerCustomEditor(String.class, "field2", new StringMultipartFileEditor("UTF-16")); binder.bind(request); assertEquals(new String(file1a.getBytes()), mtb2.getField1()[0]); assertEquals(new String(file1b.getBytes()), mtb2.getField1()[1]); assertEquals(new String(file2.getBytes(), "UTF-16"), mtb2.getField2()); resolver.cleanupMultipart(request); assertTrue(((MockFileItem) file1a.getFileItem()).deleted); assertTrue(((MockFileItem) file1b.getFileItem()).deleted); assertTrue(((MockFileItem) file2.getFileItem()).deleted); resolver.setEmpty(true); request = resolver.resolveMultipart(originalRequest); binder.setBindEmptyMultipartFiles(false); String firstBound = mtb2.getField2(); binder.bind(request); assertTrue(mtb2.getField2().length() > 0); assertEquals(firstBound, mtb2.getField2()); request = resolver.resolveMultipart(originalRequest); binder.setBindEmptyMultipartFiles(true); binder.bind(request); assertTrue(mtb2.getField2().length() == 0); }
@Override protected void initBinder(ServletRequest request, ServletRequestDataBinder binder) throws Exception { super.initBinder(request, binder); binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); }
/** * See http://www.mkyong.com/spring-mvc/spring-mvc-failed-to-convert-property-value-in-file-upload-form/ * <p></p> * Fixes this error message: * "Cannot convert value of type [org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile] to required type [byte] for property 'bytes[0]'" */ @InitBinder protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws ServletException { logger.info("initBinder"); binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); }