grails - display flash message

后端 未结 4 1294
我寻月下人不归
我寻月下人不归 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:35

    Strict answer : Just return your message (or render with a model map)

    for your controller :

    def delete() {
    
        def instanceToDelete= Myobject.get(params.id)
        try {
            instanceToDelete.delete(flush: true)
            redirect(action: "list", id: params.id)
        }
        catch (DataIntegrityViolationException e) {
            render view:'delete', model:[message: "some message"]
            //I want to refresh the div containing the flash.message here
        }
    }
    

    for your gsp :

    
        
    ${message}

    But Gregg is right, you should never modify client data without a redirect. If you do, the user might refresh (or come back to) the same url, and attempt again same action accidentally. You should really do like in hitt5's answer.

提交回复
热议问题