Skip to content

Commit

Permalink
Polish Thymeleaf templates.
Browse files Browse the repository at this point in the history
Make sure we use the suggested fragment inclusion syntax. Use th:insert instead of th:include. Use simpler URI path segment templating to avoid duplication of expressions.

Avoid trailing slashes in URIs creates as upcoming Spring Boot versions will not map the trailing slash flavors of defined URI mappings.
  • Loading branch information
odrotbohm committed Oct 25, 2022
1 parent a5cbb85 commit 9ecdc11
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/main/resources/templates/fragments/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@

<ul class="nav navbar-nav me-auto">

<li th:replace="::menuItem ('/','home','home page','home','Home')">
<li th:replace="~{::menuItem ('/','home','home page','home','Home')}">
<span class="fa fa-home" aria-hidden="true"></span>
<span>Home</span>
</li>

<li th:replace="::menuItem ('/owners/find','owners','find owners','search','Find owners')">
<li th:replace="~{::menuItem ('/owners/find','owners','find owners','search','Find owners')}">
<span class="fa fa-search" aria-hidden="true"></span>
<span>Find owners</span>
</li>

<li th:replace="::menuItem ('/vets.html','vets','veterinarians','th-list','Veterinarians')">
<li th:replace="~{::menuItem ('/vets.html','vets','veterinarians','th-list','Veterinarians')}">
<span class="fa fa-th-list" aria-hidden="true"></span>
<span>Veterinarians</span>
</li>

<li
th:replace="::menuItem ('/oups','error','trigger a RuntimeException to see how it is handled','exclamation-triangle','Error')">
th:replace="~{::menuItem ('/oups','error','trigger a RuntimeException to see how it is handled','exclamation-triangle','Error')}">
<span class="fa exclamation-triangle" aria-hidden="true"></span>
<span>Error</span>
</li>
Expand All @@ -73,7 +73,7 @@
<div class="container-fluid">
<div class="container xd-container">

<th:block th:include="${template}" />
<th:block th:insert="${template}" />

<br />
<br />
Expand Down
12 changes: 4 additions & 8 deletions src/main/resources/templates/owners/ownerDetails.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ <h2>Owner Information</h2>
</tr>
</table>

<a th:href="@{{id}/edit(id=${owner.id})}" class="btn btn-primary">Edit
<a th:href="@{__${owner.id}__/edit}" class="btn btn-primary">Edit
Owner</a>
<a th:href="@{{id}/pets/new(id=${owner.id})}" class="btn btn-primary">Add
<a th:href="@{__${owner.id}__/pets/new}" class="btn btn-primary">Add
New Pet</a>

<br />
Expand Down Expand Up @@ -65,12 +65,8 @@ <h2>Pets and Visits</h2>
<td th:text="${visit?.description}"></td>
</tr>
<tr>
<td><a
th:href="@{{ownerId}/pets/{petId}/edit(ownerId=${owner.id},petId=${pet.id})}">Edit
Pet</a></td>
<td><a
th:href="@{{ownerId}/pets/{petId}/visits/new(ownerId=${owner.id},petId=${pet.id})}">Add
Visit</a></td>
<td><a th:href="@{__${owner.id}__/pets/__${pet.id}__/edit}">Edit Pet</a></td>
<td><a th:href="@{__${owner.id}__/pets/__${pet.id}__/visits/new}">Add Visit</a></td>
</tr>
</table>
</td>
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/templates/owners/ownersList.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@ <h2>Owners</h2>
<span>Pages:</span>
<span>[</span>
<span th:each="i: ${#numbers.sequence(1, totalPages)}">
<a th:if="${currentPage != i}" th:href="@{'/owners/?page=' + ${i}}">[[${i}]]</a>
<a th:if="${currentPage != i}" th:href="@{'/owners?page=' + ${i}}">[[${i}]]</a>
<span th:unless="${currentPage != i}">[[${i}]]</span>
</span>
<span>]&nbsp;</span>
<span>
<a th:if="${currentPage > 1}" th:href="@{'/owners/?page=1'}" title="First"
<a th:if="${currentPage > 1}" th:href="@{'/owners?page=1'}" title="First"
class="fa fa-fast-backward"></a>
<span th:unless="${currentPage > 1}" title="First" class="fa fa-fast-backward"></span>
</span>
<span>
<a th:if="${currentPage > 1}" th:href="@{'/owners/?page=' + ${currentPage - 1}}" title="Previous"
<a th:if="${currentPage > 1}" th:href="@{'/owners?page=__${currentPage - 1}__'}" title="Previous"
class="fa fa-step-backward"></a>
<span th:unless="${currentPage > 1}" title="Previous" class="fa fa-step-backward"></span>
</span>
<span>
<a th:if="${currentPage < totalPages}" th:href="@{'/owners/?page=' + ${currentPage + 1}}" title="Next"
<a th:if="${currentPage < totalPages}" th:href="@{'/owners?page=__${currentPage + 1}__'}" title="Next"
class="fa fa-step-forward"></a>
<span th:unless="${currentPage < totalPages}" title="Next" class="fa fa-step-forward"></span>
</span>
<span>
<a th:if="${currentPage < totalPages}" th:href="@{'/owners/?page=' + ${totalPages}}" title="Last"
<a th:if="${currentPage < totalPages}" th:href="@{'/owners?page=__${totalPages}__'}" title="Last"
class="fa fa-fast-forward"></a>
<span th:unless="${currentPage < totalPages}" title="Last" class="fa fa-step-forward"></span>
</span>
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/templates/vets/vetList.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ <h2>Veterinarians</h2>
<span>Pages:</span>
<span>[</span>
<span th:each="i: ${#numbers.sequence(1, totalPages)}">
<a th:if="${currentPage != i}" th:href="@{'/vets.html/?page=' + ${i}}">[[${i}]]</a>
<a th:if="${currentPage != i}" th:href="@{'/vets.html?page=__${i}__'}">[[${i}]]</a>
<span th:unless="${currentPage != i}">[[${i}]]</span>
</span>
<span>]&nbsp;</span>
<span>
<a th:if="${currentPage > 1}" th:href="@{'/vets.html/?page=1'}" title="First"
<a th:if="${currentPage > 1}" th:href="@{'/vets.html?page=1'}" title="First"
class="fa fa-fast-backward"></a>
<span th:unless="${currentPage > 1}" title="First" class="fa fa-fast-backward"></span>
</span>
<span>
<a th:if="${currentPage > 1}" th:href="@{'/vets.html/?page=' + ${currentPage - 1}}" title="Previous"
<a th:if="${currentPage > 1}" th:href="@{'/vets.html?page=__${currentPage - 1}__'}" title="Previous"
class="fa fa-step-backward"></a>
<span th:unless="${currentPage > 1}" title="Previous" class="fa fa-step-backward"></span>
</span>
<span>
<a th:if="${currentPage < totalPages}" th:href="@{'/vets.html/?page=' + ${currentPage + 1}}" title="Next"
<a th:if="${currentPage < totalPages}" th:href="@{'/vets.html?page=__${currentPage + 1}__'}" title="Next"
class="fa fa-step-forward"></a>
<span th:unless="${currentPage < totalPages}" title="Next" class="fa fa-step-forward"></span>
</span>
<span>
<a th:if="${currentPage < totalPages}" th:href="@{'/vets.html/?page=' + ${totalPages}}" title="Last"
<a th:if="${currentPage < totalPages}" th:href="@{'/vets.html?page=__${totalPages}__'}" title="Last"
class="fa fa-fast-forward"></a>
<span th:unless="${currentPage < totalPages}" title="Last" class="fa fa-fast-forward"></span>
</span>
Expand Down

0 comments on commit 9ecdc11

Please sign in to comment.