0

I have a MVC application based on spring-boot:2.5.4.

After migrating from spring-boot 2.5.4, to 2.5.14-2.6.7 Thymeleaf layout does'nt import header (header tag is empty) and leaves blank other inserted elements( like layouts/sidebar :: sidebar, layouts/footer :: footer) from the decorator.

I have upgraded my libs to:

    <dependency>
        <groupId>nz.net.ultraq.thymeleaf</groupId>
        <artifactId>thymeleaf-layout-dialect</artifactId>
        <version>3.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity5</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

Main layout:

<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <!-- JS/ CSS-->
</head>
<body id="page-top">

    <div th:replace="layouts/sidebar :: sidebar"></div>

    <div id="content-wrapper" class="d-flex flex-column">
        <div id="content">
          <div layout:fragment="content"></div>
        </div>
        <footer class="sticky-footer bg-white">
            <div th:replace="layouts/footer :: footer">
            </div>
        </footer>
    </div>
</div>

and Page uwing this layout:

<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="layouts/base_layout"
      xmlns:th="http://www.thymeleaf.org">
<body>
<section layout:fragment="content">
       some content
</section>
</body>
</html>

Has there been a change in spring-boot thymeleaf compability? When I define header a sa fragment, I can import header to the pages, but this is missing the point of having a layout class, when I have to import every element manually.

Beri
  • 11,470
  • 4
  • 35
  • 57

1 Answers1

3

I was albe to fix my issue by reading migration notes for Thymeleaf.

The section:

This was deprecated back in 2.0 (thymeleaf-layout-dialect/issues/95) in favour of decorate as the naming was misleading, and has now been deleted.

So after replacing

layout:decorator

with

layout:decorate

Everything works fine.

Beri
  • 11,470
  • 4
  • 35
  • 57
  • Thank you! I read the notes too but somehow skimmed over it. Cost me more hours than I'd like to admit :D – ch1ll Feb 23 '23 at 11:16