Spring MVC : form:errors tag
How can I check for a particular error on a JSP page and only show it when it is present.
For example I would like to check whether the followi开发者_如何转开发ng error exists using <c:if>
tag and only then render it as HTML.
<form:errors path="transactionType" cssClass="error"></form:errors>
Use the <spring:hasBindErrors name="myFormBean">
tag, and inspect the page-scope errors bean.
Reference doc link
You already get this functionality with the <form:errors>
tag. It only renders its contents when there is a corresponding error (based on the path
attribute), so it is analogous to using a <c:if>
to first check for an error.
精彩评论