grails - display flash message

后端 未结 4 1286
我寻月下人不归
我寻月下人不归 2021-02-14 05:41

I’m new to Grails, and I have a question that should be easy for most of you.

I have a page displaying an object list. I want to display a message if there’

4条回答
  •  太阳男子
    2021-02-14 06:15

    The flash object is a Map which stores key/value pairs, so you can define your own key for error messages. For example:

    try {
        instanceToDelete.delete(flush: true)            
        flash.message = "successfully deleted object"
     }
     catch (DataIntegrityViolationException e) {
        flash.error = "could not delete object"            
     }
    redirect(action: "list", id: params.id)
    

    Then you can check the flash object containing the error key, and use a different style for that kind of message:

    
      
    ${flash.error}
    ${flash.message}

提交回复
热议问题