Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Using the same example we used in Example Command Object and Form and the changes made in Data Bound Form Labels, we go a little bit further and remove some message codes. 

Rabbtor enables you to define custom display names for your properties so you can just use them until you create message keys for localization. If your application does not need multi language functionality in near feature, this will save time and maintaining the labels will be easier because

they stay on the command objects. 

Now let's first remove some message keys first:

messages.properties

 

Code Block
NotEmpty={0} can not be empty.
NotNull={0} can not be null.

 

And we update the command objects to use default model names:

Code Block
languagegroovy
class RegisterCommand
{

    @NotEmpty
    @DisplayName("Name")
    String name

    @NotNull
    @DisplayName("Department")
    Long department

    @Valid
    List<AddressCommand> addresses = []

    RegisterCommand()
    {
        // Add one address to be displayed on form
        addresses.add( new AddressCommand())
    }
}

class AddressCommand
{

    @NotEmpty
    @DisplayName("Zipcode")
    String zipcode

}

We haven't made any changes in the register.jsp page given on Data Bound Form Labels page.

So now when we open the page and submit the form, we see the following screen:

Rabbtor used the default display names for the properties which don't have corresponding message keys in messages.properties file. 

So do we really need an annotation for this ? Can't we just write a utility method to get the property name, separate it to words and make it title case ? 

Well if you ask this question, that means English is your first language. For all the others who develop applications in English but target a different language, this is definitely not the case. 

And even though your first language is English, Rabbtor already provides this functionality with its metadata caching API, multiple message code generation based on property names and their declaring classes, automatic label generation and so on.