Questions tagged [spring-mvc-initbinders]

66 questions
2
votes
1 answer

Customize form bean creation process in spring

I have the following bean: public class TerminalAdmin { @Id @Column(name = "admin_id", nullable = false, unique = true) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_id") @SequenceGenerator(name = "user_id",…
gstackoverflow
  • 31,683
  • 83
  • 267
  • 574
2
votes
1 answer

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

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,…
atani
  • 53
  • 6
2
votes
1 answer

Spring MVC - @ init binder method not called

Hi this is my controller @RequestMapping(value="/home", method = RequestMethod.POST) public String homeSubmit(@Valid LoginForm loginForm , BindingResult bindResult){ if(bindResult.hasErrors() || bindResult.hasFieldErrors() ){ return…
Renganathan V
  • 353
  • 1
  • 6
  • 27
2
votes
1 answer

Spring StringTrimmerEditor trim all fields except password field

In registered a StringTrimmerEditor in a Spring controller. Of course when I now enter a password starting or ending with whitespace it is trimmed as well. But an user doesn't recognize this trimming. @InitBinder public void initBinder(WebDataBinder…
Marcel Binder
  • 156
  • 10
2
votes
1 answer

Spring 4 ControllerAdvice and InitBinder

I'm trying to register a global InitBinder using an @InitBinder annotated method inside a @ControllerAdvice class. package com.myapp.spring.configuration; import org.springframework.web.bind.WebDataBinder; import…
Paul
  • 133
  • 2
  • 9
2
votes
1 answer

Bind a nested Bean to a null if all its properties are empty in Spring MVC

Let's assume I have an Account class, that has a instance variable of Person class. public class Account { private String accountId; private Person person; // getters and setters } public class Person { private String name; // getters…
Spase Markovski
  • 583
  • 1
  • 6
  • 21
2
votes
2 answers

spring mvc one init binder for all controllers

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…
Udy
  • 2,352
  • 3
  • 19
  • 32
1
vote
0 answers

Making a getAsText() with Date in PropertyEditorSupport and @Initbinder

I need to convert date with pattern "yyyy-MM-dd" to String format "dd.MM.yyyy". Now i have this. Method getAsText() doesn't work meanwhile setAsText working. What i do wrong? DateEditor.java @Component public class DateEditor extends…
1
vote
1 answer

Java bean validation not working with web init binder

I have a controller looks like this: @RestController @RequestMapping(value="/api/events") public class EventController{ @Inject private EventValidator eventValidator; @InitBinder @Qualifier("eventValidatior") private void…
hades
  • 3,200
  • 5
  • 28
  • 56
1
vote
2 answers

view Calendar Objects in thymeleaf forms as date types

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() { …
user641887
  • 1,350
  • 2
  • 26
  • 46
1
vote
1 answer

Can a method annotated with @InitBinder be marked as static?

Looking at the docs and several examples of @InitBinder online, I never see these methods marked as static. My IDE is claiming they can be marked as static, I don't see any errors while doing so, and conceptually I would think you can mark it this…
vphilipnyc
  • 6,607
  • 6
  • 44
  • 70
1
vote
1 answer

Spring initbinder register multiple custom editor String.class

I have following initBinder in my ControllerAdvice class @InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); …
Marek Sekyra
  • 135
  • 2
  • 9
1
vote
0 answers

Spring initBinder not invoking CustomDateEditor

I am trying to bind string input form parameter to the date property of a bean using following code. I want to bind the date formatter only to a specific property named registrationDate of the bean User. I have tried various ways to specify the…
ivish
  • 402
  • 7
  • 29
1
vote
2 answers

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 =…
gstackoverflow
  • 31,683
  • 83
  • 267
  • 574
1
vote
0 answers

Example to understand a possible invalid date through a CustomDateEditor with the exactDateLength option

According with the CustomDateEditor API for this constructor version: public CustomDateEditor(DateFormat dateFormat, boolean allowEmpty, int exactDateLength) says: Without an "exactDateLength"…
Manuel Jordan
  • 11,959
  • 15
  • 69
  • 111