[英]Cannot display the validation message outside the form tag
我无法在表单标签之外显示验证消息。
@PostMapping("/for_office/office_modify")
public String updateOffice(
Locale locale,
Model model,
RedirectAttributes attrs,
@Valid @ModelAttribute Office office,
BindingResult bindingResult)
throws ParseException {
attrs.addFlashAttribute("templateName", ViewNameConst.OFFICE_VIEW_NAME);
if (bindingResult.hasErrors()) {
logger.info("OfficeController:updateOffice:hasErrors");
logger.info(bindingResult.toString());
return ViewNameConst.OFFICE_VIEW_NAME;
}
...
}
<ul class="errMsg text-danger" th:if="${#fields.hasErrors('${office}')}">
<li th:each="err : ${#fields.errors('${office}')}" th:text="${err}">
Input is incorrect
</li>
</ul>
我认为您的模板中有错误的语法。 尝试显示所有错误:
<div class="text-danger" th:if="${#fields.hasErrors('*')}">
<p th:each="err : ${#fields.errors('*')}" th:text="${err}"></p>
</div>
我不知道您的 Office model,但您可以针对个别错误尝试此操作:
<p th:if="${#fields.hasErrors('yourModelInstance.propertyName')}"
class="label label-danger" th:errors="*{yourModelInstance.propertyName}">Error here</p>
我无法解决这个问题,我解决了这个问题。 我将错误消息放在表单标签内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.