message
目的 Purpose
Resolves a message from the given code or error. Normally used in conjunction with eachError使用例 Examples
Loop through each error and output the message:<g:eachError bean="${book}"> <li><g:message error="${it}" /></li> </g:eachError>
This is typically used for built-in Grails messages, rather than user application messages. For user application messages, use theOutput a message for a specific known code:code
ormessage
parameters as illustrated below.
<g:message code="my.message.code" />
<g:message message="${myObj}" />
Objects passed to the message parameter must implement the MessageSourceResolvable interface.
詳細 Description
属性 Attributes
error
(optional) - The error to resolve the message for. Used for built-in Grails messages.code
(optional) - The code to resolve the message for. Used for custom application messages.message
(optional) - The object to resolve the message for. Objects must implementMessageSourceResolvable
.default
(optional) - The default message to output if the error or code cannot be found inmessages.properties
.args
(optional) - A list of argument values to apply to the message whencode
is used.encodeAs
(optional) - The name of a codec to apply, i.e. HTML, JavaScript, URL etclocale
(optional) OverrideLocale
to use instead of the one detected
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"
book.delete.message="Book {0} deleted."
<g:message code="${flash.message}" args="${flash.args}"
default="${flash.default}"/>
messages.properties
, your default message of "book deleted" would be output.