I have code:
<spring:hasBindErrors name="formTest">
<c:forEach items="${errors.globalErrors}" var="error">
<spring:message code="${error.code}" /><br/>
</c:forEach>
</spring:hasBindErrors>
So I pass ${errors} from Spring.
How can I check in JavaScript whether errors exist not? I tried:
<script type="text/javascript">
var NO_ERRORS = ${errors.errorCount? true :false};
</script>
But I always have: false (even if errors are exists)
I tried too:
<script type="text/javascript">
var NO_ERRORS = <c:if test="{empty errors}">true</c:if><c:if test="{not empty errors}">false</c:if>;
</script>
And: (here I always true)
<script type="text/javascript">
var NO_ERRORS = ${empty errors? true :false};
</script>
Ok I have:
<spring:hasBindErrors name="formModel">
<c:set var="isError" value="${errors.errorCount == 0}" />
<c:if test="${isError}">
<script type="text/javascript">
IS_ERRORS = false;
</script>
</c:if>
</spring:hasBindErrors>
But it is wrong, because does not work this: <c:set var="isError" value="${errors.errorCount == 0}" /> if I change to <c:set var="isError" value="${errors.errorCount > 0}" /> is good, but why firstly solution does not work?
assuming you save
errorsonly if error exists. Else you can check based onerrors.errorCount==0anderrors.errorCount>0