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

前端 未结 3 509
暗喜
暗喜 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:51

    Did you try tag (I don't understand what you mean writing "without using form taglib")?

    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
    
    
      
        
      
    
    
    

    Edit after comments:

    Inside tag there is errors variable (see Errors interface) bound to actual binding errors. You can check if field has errors via errors.hasFieldErrors(fieldName).


    And really obscure way to get field errors without any tag is requestScope['org.springframework.validation.BindingResult.yourCommandName'].hasFieldErrors('username')...

提交回复
热议问题