在表格外显示弹簧表格错误 [英] Displaying spring form error outside of form

查看:103
本文介绍了在表格外显示弹簧表格错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在表格之外显示表格错误.我知道可以使用<sf:errors path="nb"></sf:errors>将其显示在表单内部.如果要在单独的div中显示它,该怎么办?我是春天的新人,所以请引导我.

How can we display form errors out side of form. I know it can be displayed inside of form using <sf:errors path="nb"></sf:errors>. If I want to display it in separate div how can I do it? I am new to spring so please guide me.

推荐答案

如果您打算同时显示所有错误消息,则可以使用以下标记库.

You could, if you're planning to display all error messages simultaneously, using the following taglib.

<%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>

类似

<spring:hasBindErrors htmlEscape="true" name="someBean">
    <c:if test="${errors.errorCount gt 0}">
    <h4>The error list :</h4>
    <font color="red">
      <c:forEach items="${errors.allErrors}" var="error">
        <spring:message code="${error.code}"
                        arguments="${error.arguments}"
                        text="${error.defaultMessage}"/><br/>
      </c:forEach>
    </font>
  </c:if>   
</spring:hasBindErrors>

请注意,标记name="someBean" > <spring:hasBindErrors/> 是绑定到表单的实际命令对象.

Note that the name attribute name="someBean" of the tag <spring:hasBindErrors/> is your actual command object which is bound to your form.

这篇关于在表格外显示弹簧表格错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆