javaspring-mvcspring-mvc-initbinders

customize binding request parameters and fileds inside the accepted to controller method bean in spring mvc


I have the following class:

public class MyDTO { 
       @NotEmpty      
       private String isKiosk;
       ...
}

and following url:

http://localhost:1234/mvc/controllerUrl?isKiosk=false

and following controller method:

@RequestMapping(method = RequestMethod.GET, produces = APPLICATION_JSON)
@ResponseBody
public ResponseEntity<List<?>> getRequestSupportKludge(@Valid final MyDTO myDTO, BindingResult bindingResult) {
    ...
}

When I stop in debug at getRequestSupportKludge method I see that myDTO.isKiosk equals null.

I cannot change the request url.

Where can I configure mapping for my request parameter ?


Solution

  • it is working after adding following binder:

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        binder.registerCustomEditor(String.class, "isKiosk", new PropertyEditorSupport() {
            public void setAsText(String name) {
                setValue(name);
            }
        });
    }