开发者

spring validation: cleanest way to makeup accompanying labels of the validated input

I'm validating the input field that's bound to path. I'm using hibernate-validator 4 for this. Now I'd like to highlight the age label so it pops out of the page (bold, red colour etc.). However I'm wondering what the cleanest way to do this is.

<spring:hasBindErrors name开发者_StackOverflow中文版="*"/> seems to be for the whole form object instead of for a specific field. Any input is appreciated.


Spring provides special jsp tags for forms, which support this task (highlighing in case of error):

For example this jsp

...
<%@ taglib prefix='form' uri='http://www.springframework.org/tags/form'%>
...
<form:form method="post"
           commandName="myCommand">
  <form:input path="name"
              cssClass="normalLayout"
              cssErrorClass="normalLayout error"/>
  <form:errors path="name"
               cssClass="errorMessage"/>
</form:form>
...

In this case: the input field uses the css class "normalLayout" if every thing is ok, and the css classes "normalLayout" and "name" if there is a validation error for the field.

form:errors is to print the error message generated while validation.

@see http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/view.html#view-jsp-formtaglib

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜