List of usage examples for org.springframework.web.bind ServletRequestDataBinder setBindEmptyMultipartFiles
public void setBindEmptyMultipartFiles(boolean bindEmptyMultipartFiles)
From source file:common.bind.CommonBindValidator.java
/** * an empty method// ww w . j a v a 2s . c o m * @param binder */ @Override protected void initBinder(ServletRequestDataBinder binder) { binder.setBindEmptyMultipartFiles(false); binder.setRequiredFields(required_fields); binder.setAllowedFields(allowed_fields); binder.setFieldMarkerPrefix("_"); binder.setFieldDefaultPrefix("!"); if (editors != null) { Iterator<Entry<String, PropertyEditor>> i = editors.entrySet().iterator(); while (i.hasNext()) { Entry<String, PropertyEditor> e = i.next(); binder.registerCustomEditor(String.class, e.getKey(), e.getValue()); } } binder.registerCustomEditor(String.class, new StringTrimmerEditor(false)); }
From source file:no.dusken.aranea.admin.control.EditPageImageController.java
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { super.initBinder(request, binder); binder.registerCustomEditor(Article.class, articleEditor); // to actually be able to convert Multipart instance to byte[] // we have to register a custom editor binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); binder.setBindEmptyMultipartFiles(false); // now Spring knows how to handle multipart object and convert them }
From source file:no.dusken.aranea.admin.control.issue.EditIssueController.java
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { super.initBinder(request, binder); binder.registerCustomEditor(Calendar.class, timeEditor); // to actually be able to convert Multipart instance to byte[] // we have to register a custom editor binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); binder.setBindEmptyMultipartFiles(false); // now Spring knows how to handle multipart object and convert them }
From source file:no.dusken.aranea.admin.control.EditBannerController.java
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder databinder) throws Exception { super.initBinder(request, databinder); databinder.registerCustomEditor(Calendar.class, calendarEditor); databinder.registerCustomEditor(BannerType.class, bannerTypeEditor); // to actually be able to convert Multipart instance to byte[] // we have to register a custom editor databinder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); databinder.setBindEmptyMultipartFiles(false); // now Spring knows how to handle multipart object and convert them }
From source file:no.dusken.aranea.admin.control.EditLoginDetailsController.java
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { super.initBinder(request, binder); binder.registerCustomEditor(List.class, "roles", rolesEditor); // to actually be able to convert Multipart instance to byte[] // we have to register a custom editor binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); binder.setBindEmptyMultipartFiles(false); }
From source file:no.dusken.aranea.admin.control.EditImageController.java
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder databinder) throws Exception { super.initBinder(request, databinder); databinder.registerCustomEditor(Person.class, personEditor); databinder.registerCustomEditor(Set.class, "tags", tagsEditor); // to actually be able to convert Multipart instance to byte[] // we have to register a custom editor databinder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); databinder.setBindEmptyMultipartFiles(false); // now Spring knows how to handle multipart object and convert them databinder.registerCustomEditor(Boolean.class, "illustration", booleanEditor); }
From source file:no.dusken.aranea.admin.control.EditPersonController.java
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { super.initBinder(request, binder); binder.registerCustomEditor(List.class, "roles", rolesEditor); binder.registerCustomEditor(Boolean.class, "showPhoneNumber", booleanEditor); binder.registerCustomEditor(Boolean.class, "showPortrait", booleanEditor); // to actually be able to convert Multipart instance to byte[] // we have to register a custom editor binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); binder.setBindEmptyMultipartFiles(false); }
From source file:no.dusken.aranea.admin.control.EditPageController.java
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { super.initBinder(request, binder); binder.registerCustomEditor(Section.class, sectionEditor); binder.registerCustomEditor(List.class, "tags", tagsEditor); binder.registerCustomEditor(Calendar.class, timeEditor); binder.registerCustomEditor(List.class, "authors", authorsEditor); // to actually be able to convert Multipart instance to byte[] // we have to register a custom editor binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); binder.setBindEmptyMultipartFiles(false); // now Spring knows how to handle multipart object and convert them /*dont allow properties like published to be binded, so that it is not possible to set published to true * by tampering with the formsubmission * *//*from w w w . jav a 2 s. c om*/ String[] disallowedFields = new String[] { "published, modified, timePublished, " + "topic, sectionPriority, frontsidePriority" }; binder.setDisallowedFields(disallowedFields); }
From source file:org.springframework.web.multipart.commons.CommonsMultipartResolverTests.java
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);/*from w w w . java2s. c o m*/ 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); assertFalse(mtb2.getField2().isEmpty()); assertEquals(firstBound, mtb2.getField2()); request = resolver.resolveMultipart(originalRequest); binder.setBindEmptyMultipartFiles(true); binder.bind(request); assertTrue(mtb2.getField2().isEmpty()); }