Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict with Thymeleaf's th:insert #30

Open
innoLabCanada opened this issue Jun 3, 2024 · 0 comments
Open

Conflict with Thymeleaf's th:insert #30

innoLabCanada opened this issue Jun 3, 2024 · 0 comments

Comments

@innoLabCanada
Copy link

innoLabCanada commented Jun 3, 2024

This isn't a "bug" with this tutorial per-se, but rather a gotcha that I was trying to solve which led me to this tutorial in an effort to figure out what I was doing wrong. If this should not be recorded here, please suggest another place to put it.

Problem: Certain Thymeleaf expressions seem to cause the page to only partially load.
Solution: Add the following to the application configuration (ie: application.properties")
spring.thymeleaf.servlet.produce-partial-output-while-processing=false

In my case, my template was taking advantage of the th:replace and th:insert attributes.

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="https://www.thymeleaf.org">

  <head th:replace="~{'fragments/headTagFragment'}"><title>Will Be Replaced</title></head>
  <body>
    <div th:replace="~{'fragments/navigation'}"></div>
    <form th:action="@{/contact}" th:object="${contactMessageDTO}" method="POST">
      <!-- boilerplate contact form -->
    </form>
    <div th:replace="~{'fragments/footer'}"></div>
  </body>
</html>

Experience:

  • When I inspected the page in the browser, I had the HTML tags and the HEAD tags, but the headTagFragment would only be partially rendered, and the degree of rendering was random.
  • The error messaging indicated a problem with the th:action in my form tag. This sent me down a rabbit hole looking for why the /contact endpoint could not be found.
  • When I removed the th:action the page would load (but of course, it would not have anywhere to submit to).
  • If I commented out my navigation fragment, the page would load (but it would not look as designed).

Setting the produce-partial-output-while-processing to false, forced the page to be fully created before rendering in the browser. That seems to have been key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant