开发者

Spring form errors custom html

I need to do something like that:

 <form:errors path="*">
        <div class="error">
                <div class="internal">
                    <a href="#" class="close"></a>
                    ${error}
开发者_开发技巧                </div>
                <div class="bar">&nbsp;</div>
                <div class="internal">
                    <input type="button" value="Ok" />
                </div>
        </div>
    </form:errors>

How can I get all the error messages by using the above HTML code? :S

By using <form:errors path="*" cssClass="error" /> it will be inside only one tag


You can use the spring:bind tag to bind a status-variable to your current error messages. Then you can iterate over status.errorMessages like in the example below.

<spring:bind path="*">
  <c:forEach items="${status.errorMessages}" var="error">
    <div class="error">
      <div class="internal">
        <a href="#" class="close"></a>
        ${error}
      </div>
      <div class="bar">&nbsp;</div>
      <div class="internal">
        <input type="button" value="Ok" />
      </div>
    </div>
  </c:forEach>      
</spring:bind>

Don't forget to add the taglib declaration for spring: tags on top of your page:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜