message

Purpose

Resolves a message from the given code or error. Normally used in conjunction with eachError. O

Examples

Loop through each error and output the message:

<g:eachError bean="${book}">
    <li><g:message error="${it}" /></li>
</g:eachError>

Note that this is typically used for built-in Grails messages, rather than user application messages. For user application messages, use the code or message parameters, as illustrated below.

Output a message for a specific known code:

<g:message code="my.message.code" />

Output a message for a compatible object.

<g:message message="${myObj}" />

Note that objects passed to the message parameter must implement the org.springframework.context.MessageSourceResolvable interface.

Description

Attributes

One of either the error attribute, the code attribute or the message attribute is required. Messages are resolved from the grails-app/i18n/messages.properties bundle. See also Internationalization.

For a more complex example, to output your own message with parameters and a default message, you might use the following code from your controller:

flash.message = "book.delete.message"
flash.args = [ "The Stand" ]
flash.default = "book deleted"

You would then specify the following in messages.properties:

book.delete.message="Book {0} deleted."

and specify the following from your view:

<g:message code="${flash.message}" args="${flash.args}" default="${flash.default}"/>

Which would result in the output "Book The Stand deleted." If you had misnamed the message or not specified it in messages.properties, your default message of "book deleted" would be output.

Source

Show Source