grails - display flash message

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

    This can help you:

    def delete() {
        def instanceToDelete= Myobject.get(params.id)
        try {
            instanceToDelete.delete(flush: true)
            flash.success = "Object deleted correctly"
        } catch (DataIntegrityViolationException e) {
            flash.error = "Something goes wrong"
        }
        redirect(action: "list", id: params.id)
    }
    

    redirect to the gsp after all the code, to can store if there is an error or everything goes well.

    you can put the messages in different variable to discriminate between error and success.

    
        
    ${flash.success}
    ${flash.error}

提交回复
热议问题