Page tree
Skip to end of metadata
Go to start of metadata

Now let's change the example form given in Example Command Object and Form 

First let's put additional message keys to our messages.properties file:

messages.properties

NotEmpty={0} can not be empty.
NotNull={0} can not be null.
zipcode=Zipcode
department=Department
registerCommand.name=Your name

And change the form to use Rabbtor's custom label JSP tag:

register.jsp

 


<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="rform" uri="http://rabbytes.com/rabbtor/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
    <body>

        <form:form modelAttribute="registerCommand" >

            <p>
                <rform:label path="name" />
                <form:input path="name" />
                <form:errors path="name" />
            </p>

            <p>
                <rform:label path="department" />
                <form:input path="department" />
                <form:errors path="department" />
            </p>

            <h3>Addresses</h3>
            <c:forEach items="${registerCommand.addresses}" var="address" varStatus="i" >
                <h5>Address: ${i.index}</h5>
                <rform:label path="addresses[${i.index}].zipcode" />
                <form:input path="addresses[${i.index}].zipcode" />
                <form:errors path="addresses[${i.index}].zipcode" />
                <br />
            </c:forEach>


            <input type="submit" value="Submit" />
        </form:form>

    </body>
</html>


 

 

 

 

So Rabbtor puts labels for the properties even for the nested ones using the same message codes in error message display names.

Till now, everything looks good. But we didn't use the model metadata fully yet. As we said, we have a @DisplayName annotation. Now let's see how it works.

 

 

  • No labels