• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

SpringMVC with Bootstrap and Thymeleaf pages decoration

 
Ranch Hand
Posts: 42
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey

I am working in:
"SpringMVC 5", with "Twitter Bootstrap 4" html pages, and "Thymeleaf 3" templating, in IntelliJ EAP (latest version) and Tomcat9, Maven

The structure of my project:


I am using these tutorials:
https://www.baeldung.com/spring-thymeleaf-fragments
https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#template-layout

I have my page (home.html). I have my template (template.html).
According to the 2nd tutorial:

1. I inserted the "menubar" into the "template" (this insert must work, because I inserted the menubar directly to the "home.html" and it was inserted successfuly)
2. Question that I cannot solve from what they say into the 2nd tutorial:
How I "decorate" my "home.html" according the "template.html". I mean, how I use the template to decorate according it all my pages?

I used the following in the "home.html" but it is not working:


My files are:

"home.html"


"menubar.html"


"template.html"


"WebConfig.java"


In my pom (some of it):


Please some one help. Thanks in advance
 
Thomas Mylonas
Ranch Hand
Posts: 42
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey finally I found solution:

Step 1

I put the page and the layout in the same folder:



Step 2

In "home.html" I added the "layout:decorate"


In "template.html" I changed the "layout:fragment"


In the "WebConfig.java" I deleted the "viewResolver() method" and I changed the others like following:


But... A problem remains. I cannot keep my pages and my layout in different folders. If I do it with the previous structure and put: layout:decorate="~{layout/template}" the page is displayed as a blank page.

Any solution and idea from you it would be perfect for me.
A part of the solution is found though.

Update:
Solution in the last part is found. I had a mistake in the "template.html".
I should put it as: "layout/fragments/menubar.html :: menubar" with the structure:

And the code will be:
 
Marshal
Posts: 74342
334
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please beware of editing; if there is an answer before your edits, that answer will look mistaken. In this case, I think nobody else noticed the edits
 
Thomas Mylonas
Ranch Hand
Posts: 42
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Cambell Ritchie

Thanks a lot for notifying me this info.

With respect
reply
    Bookmark Topic Watch Topic
  • New Topic