Is there a way to make a domain class name human readable in Groovy/Grails? For example, I might have a class called LibraryBook and in the application views, it will be shown as “Create LibraryBook”. Is it possible to make Grails show this as “Create Library Book”?
Share
If you look at the top of your
grails-app/views/libraryBook/create.gspfile, you will see something like:This shows you can set a
libraryBook.labelmessage property to override the default name ofLibraryBook. This property should be set in thegrails-app/i18n/message.propertiesfile. The documentation for this can be found here.As an interesting aside (and not the recommended best practice), you can alter the default grails scaffolding templates. First, you need to install the templates with:
Then, you can edit the file
src/templates/scaffolding/create.gsp(andlist.gsp, etc) and change the line:to
As you can see, this code:
Takes the CamelCase classname, and replaces all capital letters (apart from the first one) with the letter following a space character.
Then when you call
generate-viewsorgenerate-all, the newly created gsp will have this default name with spaces in it