здесь мой контроллер:
@RequestMapping("category/view/{id}")
public String viewCategory(@PathVariable("id") int id, Model model) {
Optional<Category> category = categoryRepository.findById(id);
logger.info("find_category = " + category);
model.addAttribute("isDisable", true);
model.addAttribute("category", category);
return "category";
}
здесь шаблон
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="${appName}">Category template title</title>
<link th:href="@{/public/style.css}" rel="stylesheet"/>
<meta charset="UTF-8"/>
</head>
<body>
<div class="container">
<h3 th:if="*{isDisable}">Disabled</h3>
<h3 th:if="*{isAdd}">Add category</h3>
<h3 th:unless="*{isAdd}">Edit category</h3>
<form method="post" action="#" th:object="${category}" th:action="@{/category}">
<input type="hidden" id="id" th:field="*{id}"/>
<input type="text" placeholder="Name" id="name" th:field="*{name}" th:disable="${isDisable}"/>
<input type="hidden" id="created" th:field="*{created}"/>
<textarea placeholder="Description" rows="5" id="description"
th:field="*{description}"></textarea>
<input type="submit" value="Submit"/>
</form>
</div>
</body>
</html>
и здесь сгенерировано html:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="/public/style.css" rel="stylesheet"/>
<meta charset="UTF-8"/>
</head>
<body>
<div class="container">
<h3>Disabled</h3>
<h3>Edit category</h3>
<form method="post" action="/category"><input type="hidden" name="_csrf" value="4fc8f3e0-f5f4-4da1-858c-fe0a9d05cdfb"/>
<input type="hidden" id="id" name="id" value="1"/>
<input type="text" placeholder="Name" id="name" disable="true" name="name" value="Toys"/>
<input type="hidden" id="created" name="created" value="08.01.2020 18:52:07"/>
<textarea placeholder="Description" rows="5" id="description" name="description">Toys's description</textarea>
<input type="submit" value="Submit"/>
</form>
</div>
</body>
</html>
, как вы можете видеть disable = "true" :
<input type="text" placeholder="Name" id="name" disable="true" name="name" value="Toys"/>
но я могу редактировать поле Имя
Почему?