Grails Editing Flash Delete Message

前端 未结 3 1747
刺人心
刺人心 2021-01-17 06:05

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

相关标签:
3条回答
  • 2021-01-17 06:44

    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.

    0 讨论(0)
  • 2021-01-17 06:51

    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
    
    0 讨论(0)
  • 2021-01-17 07:06

    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
    
    0 讨论(0)
提交回复
热议问题