我正在学习thymeleaf验证部分,我得到的错误如下
异常计算SpringEL表达式:“#fields.hasErrors(‘职务标题’)”(身份验证/联系人:19)
我的表单有以下字段
<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>当我删除职务头衔时,它的工作状态良好。
我的验证器类如下所示
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");
}有什么问题我无法辨认!请帮帮忙
发布于 2015-11-08 21:42:24
问题就在后面。
<span class="error" th:if="${#fields.hasErrors('email')}" th:errors="email"></span>它必须是
th:errors="*{email}"与下面代码中的这一行相同
<span class="error" th:if="${#fields.hasErrors('jobtitle')}" th:errors="*{jobtitle}"></span>https://stackoverflow.com/questions/18653811
复制相似问题