Spring MVC Error Messages

后端 未结 3 624
情书的邮戳
情书的邮戳 2021-02-09 17:42

Spring MVC Error Messages

Hello, Spring Fellows,

I have a form that is validated by the Spring Validation once submitted. Each field on the form may contain mult

相关标签:
3条回答
  • 2021-02-09 17:44

    The simplest answer is to not use tables for page layout. Utilizing div tags alleviates this problem altogether since divs are completely dimensionless if set to hidden.

    0 讨论(0)
  • 2021-02-09 18:05

    You can do something like this (notice that bind is from spring taglib):

    <spring:bind path = "name*">
        <c:if test="${status.error}"> 
            <tr> 
                <td> 
                    <form:errors path="name*" /> 
                </td> 
            </tr> 
        </c:if> 
    </spring:bind>
    
    0 讨论(0)
  • 2021-02-09 18:06

    I solved your problem by doing this:

    <table>
        <form:errors path="firstName">
        <tr>
            <td colspan="2">
                <form:errors path="firstName"/>
            </td>
        </tr>
        </form:errors>
        <tr>
            <td><form:label path="firstName"><spring:message code="helloworld.label.firstName"/></form:label></td>
            <td><form:input path="firstName"/></td>
        </tr>
    </table>
    

    errors tag body will be evaluated only if there are errors on the path.

    0 讨论(0)
提交回复
热议问题