spring-mvc-initbinders

org.springframework.validation.BeanPropertyBindingResult Exception

早过忘川 提交于 2020-01-13 11:09:18
问题 Hi I am a new to spring framework. I have done a small example where I tried to validate my input field using spring validation api. This is the code @RequestMapping(value = "/applicationFormSubmit", method = RequestMethod.POST) public String insertdata( @ModelAttribute("applicationForm") @Valid ApplicationFormBean applicationFormBean, @RequestParam("file") MultipartFile file, BindingResult result,Model model) { if(result.hasErrors()) { return "applicationForm"; } try { Blob blob = Hibernate

Failed to convert value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type

耗尽温柔 提交于 2020-01-11 09:42:55
问题 I have following controller method: @RequestMapping(value = "/owner/terminals/save", method = RequestMethod.POST) public String saveTerminal( @RequestParam(value = "name") String name, @RequestParam(value = "file") @Valid OnlyForImagesFileWrapper file, BindingResult bindingResult ) { ... and I see the following stacktrace: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type

Failed to convert value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type

喜欢而已 提交于 2020-01-11 09:42:09
问题 I have following controller method: @RequestMapping(value = "/owner/terminals/save", method = RequestMethod.POST) public String saveTerminal( @RequestParam(value = "name") String name, @RequestParam(value = "file") @Valid OnlyForImagesFileWrapper file, BindingResult bindingResult ) { ... and I see the following stacktrace: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type

view Calendar Objects in thymeleaf forms as date types

China☆狼群 提交于 2019-12-24 08:03:01
问题 I have a user object, and the User is having a field DOB (Date of Birth) I have stored that field as a calendar inside the User BO. Something like this: public class UserBO { private Calendar dateOfBirth; public Calendar getDateOfBirth() { return dateOfBirth; } public void setDateOfBirth(Calendar dateOfBirth) { this.dateOfBirth = dateOfBirth; } } Now I need to display this field as a Date field in thymeleaf and not a text field. I need a date field since I like the date picker :) This is what

@Valid annotation is ignored when applied to MultipartFile object

半城伤御伤魂 提交于 2019-12-23 12:28:40
问题 This is my controller. It accepts a multipart/form-data request with two fields, form and file . The form field is a MyObject , the file field is a MultipartFile . Both variables are annotated with @Valid , and accordingly, I would expect Spring to invoke the Validator class of each respective field. However, this only happens with MyObject , and not with MultipartFile . @RequestMapping("/api") @RestController public class Controller { private MyObjectRepository repo; private

Spring mvc miss id of dependent collection when combine form object from jsp

大憨熊 提交于 2019-12-12 10:38:00
问题 I have following controller to return view: @RequestMapping(value = "/admin/adminUsers", method = RequestMethod.GET) public String adminUsers(ModelMap model, HttpSession session) { Set<TerminalAdmin> users = terminalAdminService.getAllAdmins(); session.setAttribute("users", users); model.addAttribute("adminRoles", terminalAdminService.findAllAdminRoles()); model.addAttribute("terminalAdmin", new TerminalAdmin()); model.addAttribute("generatedPassword", PasswordUpdateStatus.generatePassword())

Spring-MVC using a Converter to load object from path variable, but need to return 404 for unfound

帅比萌擦擦* 提交于 2019-12-10 22:58:05
问题 TL;DR - Is there a way to throw an error from a registered type converter during the MVC databinding phase such that it will return a response with a specific HTTP status code? I.e. if my converter can't find an object from the conversion source, can I return a 404? I have a POJO: public class Goofball { private String id = "new"; // others public String getName () { ... } public void setName (String name) { ... } } and am using a StringToGoofballConverter to create an empty object when "new"

Customize mapping request parameters and fields inside the DTO ?

无人久伴 提交于 2019-12-10 01:52:33
问题 I have the following class: public class MyDTO { private String kiosk; ... } and following url: http://localhost:1234/mvc/controllerUrl?kiosk=false and following controller method: @RequestMapping(method = RequestMethod.GET, produces = APPLICATION_JSON) @ResponseBody public ResponseEntity<List<?>> getRequestSupportKludge(final MyDTO myDTO, BindingResult bindingResult) { ... } Now it is working nice and boolean field resolves properly. Now url parameter has changed like this: http://localhost

spring mvc one init binder for all controllers

牧云@^-^@ 提交于 2019-12-08 02:01:40
问题 I have 5 controllers and i would like to register an InitBinder to all of them. I know i can add this code to each of them. @InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(StringWrapper.class, new StringWrapperEditor()); } But i would like to define it only once (even create a bean of StringWrapperEditor and use it instead of creating new every time.) I searched SO and some other places but didn't find any answear. Is it even possible? Im using spring 3

spring mvc one init binder for all controllers

☆樱花仙子☆ 提交于 2019-12-06 08:23:57
I have 5 controllers and i would like to register an InitBinder to all of them. I know i can add this code to each of them. @InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(StringWrapper.class, new StringWrapperEditor()); } But i would like to define it only once (even create a bean of StringWrapperEditor and use it instead of creating new every time.) I searched SO and some other places but didn't find any answear. Is it even possible? Im using spring 3.1.1 with java 1.6. Implement a PropertyEditorRegistrar which registers all your custom PropertyEditors