How to access Spring 3 MVC validator results in JSP without using form taglib

前端 未结 3 502
暗喜
暗喜 2021-02-04 08:08

I have a simple Spring 3 MVC form using jsp taglibs. I need to add a class based on whether a field within the form has any errors associated with it or not. Here is a snipet

3条回答
  •  囚心锁ツ
    2021-02-04 08:47

    There is a better way to get the error message

    
        ${errors.hasFieldErrors('userId') ? errors.getFieldError('userId').defaultMessage : ''}
    
    

    And one liner

     ${requestScope['org.springframework.validation.BindingResult.user'].hasFieldErrors('emailId') ? requestScope['org.springframework.validation.BindingResult.user'].getFieldError('emailId').defaultMessage : ''}
    

提交回复
热议问题