Resolve issue on white space in validation(Spring validation)
In the above form we need to fill all required fields to submit the form. In some case we able to by pass the form by using white spaces. But the application could not able to allow the user to submit with white space.
For resolve this issue we can use @InitBinder in spring. This @InitBinder will
- Pre-process every string form data
- Remove leading and trailing white space
- If string only has white space ... trim it to null
For use this @InitBinder we need to initBinder method in the Controller.
@InitBinder
public void initBinder(WebDataBinder dataBinder) {
StringTrimmerEditor stringTrimmerEditor = new StringTrimmerEditor(true);
dataBinder.registerCustomEditor(String.class, stringTrimmerEditor);
}
By using this we can resolve the issue
Comments
Post a Comment