manu
manu

Reputation: 263

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 following error exists using <c:if> tag and only then render it as HTML.

<form:errors path="transactionType" cssClass="error"></form:errors>

Upvotes: 0

Views: 8375

Answers (2)

Axel Fontaine
Axel Fontaine

Reputation: 35169

Use the <spring:hasBindErrors name="myFormBean"> tag, and inspect the page-scope errors bean.

Reference doc link

Upvotes: 6

earldouglas
earldouglas

Reputation: 13473

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.

Upvotes: 5

Related Questions