Deprecated unwrapped fragment expression
Asked Answered
C

1

6

Hi While clicking on register button using thymeleaf 3.1 and spring6 i am getting the following error can someone help me out on this how to write in the new version the given syntax

base::layout(~{::section})

Deprecated unwrapped fragment expression "base::layout(~{::section})" found in template register.html, line 2, col 53. Please use the complete syntax of fragment expressions instead ("~{base::layout(~{::section})}"). The old, unwrapped syntax for fragment expressions will be removed in future versions of Thymeleaf.

Below is my register.html file

<!DOCTYPE html>
<html  lang="en" xmlns:th="http://www.thymeleaf.org" 
       th:replace="base::layout(~{::section})">
<head>
    <meta charset="ISO-8859-1">
    <title>Insert title</title>
</head>
<body>
    <section>
        <div class="container p-3" >
            <div class="row">
                <div class="col-md-6 offset-md-3">
                    <div class="card">
                        <div class="card-header text-center fs-4">Register Page</div>
                        <th:block th:if="${session.msg}">
                            <p class="text-center fs-3">[[${session.msg}]]</p>
                            <th:block th:text="${#session.removeAttribute('msg')}" </th:block>
                            </th:block>
                        <div class="card-body">
                            <form action="createUser" method="post">
                                <div class="mb-3">
                                    <label>Enter First Name</lable>
                                        <input type="text" name="firstname" class="form-control">
                                </div>
                                <div class="mb-3">
                                    <label>Enter Middle Name</lable>
                                        <input type="text" name="middlename" class="form-control">
                                </div>
                                <div class="mb-3">
                                    <label>Enter Last</lable>
                                        <input type="text" name="lastname" class="form-control">
                                </div>
                                <div class="mb-3">
                                    <label>Enter Username</lable>
                                        <input type="text" name="username" class="form-control">
                                </div>
                                <div class="mb-3">
                                    <label>Enter Password</lable>
                                        <input type="text" name="password" class="form-control">
                                </div>
                                <div class="mb-3">
                                    <label>Enter Address</lable>
                                        <input type="text" name="address" class="form-control">
                                </div>
                                <button class="btn btn-primary col-md-12">Register</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</body>
</html>

here is the base.html from which i am trying to access

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:fragment="layout(content)">
<head>
<meta charset="ISO-8859-1">
<title>Insert title</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body class="bg-light">
<h1>Base Page</h1>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">User Management</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="/">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="/register">Register</a>
        </li>
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="/login">Login</a>
        </li>
      </ul>
    </div>
  </div>
</nav>
<div th:insert="${content}"></div>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
</body>
</html>

trying to register the user and get response register successfully in frontend

Caa answered 19/3, 2023 at 4:43 Comment(0)
L
9

Just replace your code:

th:replace="base::layout(~{::section})"

with :

th:replace="~{base::layout(~{::section})}"

it will work now.

Lunation answered 6/4, 2023 at 8:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.