簡體   English   中英

胸腺驗證

[英]Thymeleaf Validation

我正在學習百里香驗證部分,但出現錯誤

評估SpringEL表達式的異常:“#fields.hasErrors('jobtitle')”(身份驗證/聯系方式: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>

當我刪除jobtitle div時,它的工作正常

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");
}

我無法識別的問題是什么!!!!!!請幫助

問題在下面

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM