I am having an issue parsing the th:field
's value to a variable of class Duration
. What I want to happen is to input some numbers and I want to be saved as minutes.
This is from my HTML
file:
<input type="text" th:field="*{duration}">
On my object's side, I just initialized the variable like:
@Column(nullable = false)
private Duration duration;
and I get an error webpage:
Validation failed for object='bookingType'. Error count: 1 org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors Field error in object 'bookingType' on field 'duration': rejected value [15]; codes [typeMismatch.bookingType.duration,typeMismatch.duration,typeMismatch.java.time.Duration,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [bookingType.duration,duration]; arguments []; default message [duration]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.time.Duration' for property 'duration'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.persistence.Column java.time.Duration] for value '15'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [15]]
I am using Bootstrap for the front-end, if it does matter at all.
I added the Thymeleaf's java8time extra
, tried changing the input type to time and number, and I still get the same error.