[英]Thymeleaf Validation
I am learning thymeleaf validation section and i got error like 我正在学习百里香验证部分,但出现错误
Exception evaluating SpringEL expression: "#fields.hasErrors('jobtitle')" (authentication/contactus:19) 评估SpringEL表达式的异常:“#fields.hasErrors('jobtitle')”(身份验证/联系方式:19)
My form has following field 我的表格有以下字段
<div class="form50">
<label for="contact.emailAddress"><span th:text="#{contact.email}">Email</span></label>
<span class="error" th:if="${#fields.hasErrors('email')}" th:errors="email"></span>
<input type="email" th:field="*{email}" class="field50" th:classappend="${#fields.hasErrors('email')}? 'fieldError'" />
</div>
<div class="form50">
<label for="customer.firstName"><span th:text="#{contact.jobtitle}">Job Title</span></label>
<span class="error" th:if="${#fields.hasErrors('jobtitle')}" th:errors="*{jobtitle}"></span>
<input type="text" th:field="*{jobtitle}" class="field50" th:classappend="${#fields.hasErrors('name')}? 'fieldError'" />
</div>
<div class="login_register">
<input class="register_button big red" type="submit" th:value="#{contact.contact}"/>
</div>
</blc:form>
when i remove jobtitle div its working fine 当我删除jobtitle div时,它的工作正常
myvalidator class looks like following myvalidator类如下所示
public void validate(Object obj, Errors errors, boolean useEmailForUsername) {
ContactCustomerForm form = (ContactCustomerForm) obj;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "name.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "emial.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "jobtitle", "jobtitle.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "country", "country.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phone", "phone.required");
}
What is the issue i cant able to identify!!!!!!Please Help 我无法识别的问题是什么!!!!!!请帮助
Problem is following line 问题在下面
<span class="error" th:if="${#fields.hasErrors('email')}" th:errors="email"></span>
it has to be 它一定要是
th:errors="*{email}"
same as this line in your code bellow 与下面的代码行相同
<span class="error" th:if="${#fields.hasErrors('jobtitle')}" th:errors="*{jobtitle}"></span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.