【发布时间】:2015-12-28 18:54:18
【问题描述】:
我需要在我页面上的same DIV 中显示 SpringMVC 的表单错误,以及我存储在请求中的任何自定义“异常”消息。
现在它们位于不同的 DIV 中:
<!-- Validation Errors -->
<spring:hasBindErrors htmlEscape="true" name="model">
<c:if test="${errors.errorCount gt 0}">
<div class="errors_div clsErrorTblBorder">
<c:forEach items="${errors.allErrors}" var="error">
<div class="errors clsWhiteBack blue">
<myForm:message messageLinkClass="errorLink"
error="${error}" />
</div>
</c:forEach>
</div>
</c:if>
</spring:hasBindErrors>
<!-- Exceptions -->
<c:if test="${fn:length(requestScope.exceptions) > 0}">
<div class="errors_div clsMsgTblBorder">
<c:forEach items="${requestScope.exceptions}" var="exception">
<div class="messages clsWhiteBack">
${exception}
</div>
</c:forEach>
</div>
</c:if>
错误 DIV 的共享条件应该是,
${fn:length(requestScope.exceptions) || errors.errorCount gt 0}
但是不可能测试这个条件,因为:
你没有得到
errorsvar。直到你做<spring:hasBindErrors><spring:hasBindErrors>中的任何内容仅适用于您拥有
绑定错误。如果您不这样做(例如,如果您只有一个自定义
异常消息)它的逻辑不会执行,所以你不能移动
自定义“异常”检查。
【问题讨论】:
标签: spring spring-mvc