• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Validating in Spring Boot with Thymeleaf

 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am creating a web application in Spring Boot with Thymeleaf and learning how to use validation; I have found several examples In the Internet that work quite well in my computer and have copied code from them. However, running my applicatio, I am getting a page with the message "Whitelabel Error Page";
I also get a very long stack trace in the console; the most important part to me are:

I searched the Internet for problems like "Neither BindingResult nor plain target object for bean name 'licensesRequest' available as request attribute" to no avail.

In tne controller I have:

The application does breack in method "public String licenses" which is called directly from the web page "GetLicenses.html" (showed ahead)", but the problem occurs when the page tries to go to "/fromLicenses" (control method showLicenses).

The important part of GetLicenses.html is:

The more I analyze, I thing that the ideas I have used are correct, although ofcourse I can be wrong; but I am surprised by a part of the message in the stacktrace saying "(template: "Admin/GetLicenses" - line 78, col 31)" because that line corresponds to a part of GetLicenses.html containing:

In the bove code I introduced the two lines indicating "line 78, col 31".

The object, LicensesRequest, does have property:

I really think that I have provide all the information needed without making this text very long, but i would be glad to provide any further information.
 
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Years ago I saw a Thymeleaf demo that threw the White Label error because an html tag wasn't properly closed.  Thymeleaf is really picky about that.  I see you don't have a closing Form tag.  Try adding one; and also check to make sure every element has a closing tag.
 
Saloon Keeper
Posts: 2450
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alejandro,
Do you have getter and setter for the property address?
It seems to me that your address cannot be found in the front end.
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Himai and Tim for your prompt reply; Yes, I have getters and setters; I changed my GetLicenses.html to a form with a simple content with the correction hat Himai indicated:

My controller is:

Regrettably, I am still getting the "Whitelabel Error Page" message; although without a stack trace.
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I discovered something very strange debugging; I found out that the code actually reaches the method @PostMapping showLicenses in the controller. For some reason bindingResult.hasErrors() was giving false and the line of code 'return "redirect:/BackToAdmin";' was being executed and then I would get the error message. I am mystified because from that point on there is no validation; I changed the code to  'return "BackToAdmin";' but I am still having the same problem. I appears I have another problem that I have to investigate.
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still need help with validation; I can live without "redirect:/BackToAdmin"; my problem is that bindingResult.hasErrors() is giving false when there is no date in the web page. The class for the model object is:

I should be getting bindingResult.hasErrors() and I should be able to display the errors.
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all. Well my original problem was solved By TIM; I have a  new problem and I am going to close this one.
 
Himai Minh
Saloon Keeper
Posts: 2450
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Alejandro,
You may need @RequestBody for the LicenseRequest:
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Himai for your prompt response. Unfortunately I am getting the error message "HTTP Status 415 – Unsupported Media Type".
 
Himai Minh
Saloon Keeper
Posts: 2450
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
First when is this error coming from? Do you have this dependency in your pom?
<dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-thymeleaf</artifactId>
 </dependency>
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I have the dependency for spring-boot-starter-thymeleaf and I also have spring-boot-starter-web.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic