Hi am new at Grails i have implemented a delete action that deleted messages in an inbox,, but now i want to change the flash message to display \"2 Messages deleted\" not
If you look up the default.deleted.message
key in your messages.properties
you'll see it looks like
default.deleted.message={0} {1} deleted
Simply add a new line with the key and value you want.
inbox.deleted.message={0} messages deleted
and use it in your controller
flash.message = message(code: 'inbox.deleted.message', args: [deletedMessageCount])
Of course, you'll need to define a value for deletedMessageCount
before using it.
You could do this:
def device = MessagingDevice.findByPhoneNumber(params.phoneNumber)
// invoke deleteFromDevice on domain object, which returns number of objects deleted
def count = messageInstance.deleteFromDevice(device)
if (count) {
flash.message = message(code: 'default.deleted.message', args: [message(code: 'message.deleted.label', default: '{0} Messages deleted'), count])
redirect(action: "phone", params:[phoneNumber:params.phoneNumber])
}
and in your messages.properties
message.deleted.label={0} deleted
in code:
int count = 5 //number of deleted messages
flash.message = message(code: 'default.deleted.messages', args: [message(code: 'messages.label', default: 'Messages'), count])
in messages.properties:
messages.label=Messages
default.deleted.messages={1} {0} deleted