Wednesday, August 2, 2017

Thymeleaf: DefaultHandlerExceptionResolver : Failed to bind request





>PROBLEM

The page fails to render and returns the following error:



2017-08-02 19:41:27.258 WARN 13112 --- [nio-8080-exec-9] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to bind request
element: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type
'br.com.setget.model.User'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed
to convert from type [java.lang.String] to type [java.lang.Long] for value 'admin@email'; nested exception is
java.lang.NumberFormatException: For input string: "admin@email"


>SOLUTION

Check the thymeleaf's html code.
HTML input tags are responsible to upload values to the server.
If the input tag is not conform to thymeleaf semantic, it may cause this kind of issue.
In this example the defective code found was:

<div>
<input type="text" placeholder="username" name="user">
</div>
<div>
<input type="password" placeholder="password" name="password">
</div>


The defective code was corrected and replaced by the following:

<div>
<input type="text" id="email" name="email" th:placeholder="email" th:field="*{email}" /></br>
</div>
<div>
<input type="password" id="password" placeholder="password or create one" name="password" th:field="*{password}">
</div>


>ENV
Spring Boot 1.5.4.RELEASE
Thymeleaf 3.0.6.RELEASE
java 8

No comments:

Post a Comment

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...