• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Validating in Spring Boot with Thymeleaf

 
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
  • 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: 91
1
  • Mark post as helpful
  • send pies
  • 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.
 
Ranch Foreman
Posts: 1903
12
  • Mark post as helpful
  • send pies
  • 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: 481
  • Mark post as helpful
  • send pies
  • 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: 481
  • Mark post as helpful
  • send pies
  • 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: 481
  • Mark post as helpful
  • send pies
  • 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: 481
  • Mark post as helpful
  • send pies
  • 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
Ranch Foreman
Posts: 1903
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Alejandro,
You may need @RequestBody for the LicenseRequest:
 
Alejandro Barrero
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
  • 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
Ranch Foreman
Posts: 1903
12
  • Mark post as helpful
  • send pies
  • 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: 481
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I have the dependency for spring-boot-starter-thymeleaf and I also have spring-boot-starter-web.
 
These are the worst of times and these are the best of times. And this is the best tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic