开发者

Grails: How does that the UPDATE function work?

开发者 https://www.devze.com 2023-01-20 11:21 出处:网络
I got rid of the original UPDATE gsp Grails offers. I put it in the first row of my list.gsp table and change all the values of the table to g:textfield so they can be edited without going to the sav

I got rid of the original UPDATE gsp Grails offers.

I put it in the first row of my list.gsp table and change all the values of the table to g:textfield so they can be edited without going to the save.gsp

But now I'm trying to make it work, and I can't.

I added a update button in the last column of the row, of every row.

When I change the values of the g:textfields and click the update button it tells me

Density #ID updated

but the values do not change.

I think I am doing something wrong with def update in the controller.

Here is the code:

def update = {
        log.info "Entering Action ${actionUri}"

        def densityInstance = Density.get(params.id)
        if (densityInstance) {

                if(params?.Rcommodity) { 
                    println "${params.Rcommodity}"

                }
            if (params.version) {
                def version = params.version.toLong()
                if (densityInstance.version > version) {

                    densityInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'density.label', default: 'Density')] as Object[], "Another user has updated this Density while you were editing")
      开发者_Python百科              render(view: "list", model: [densityInstance: densityInstance])
                    return
                }
            }
            densityInstance.properties = params
            if (!densityInstance.hasErrors() && densityInstance.save(flush: true)) {
                flash.message = "${message(code: 'default.updated.message', args: [message(code: 'density.label', default: 'Density'), densityInstance.id])}"
                redirect(action: "list", id: densityInstance.id)
            }
            else {
                redirect(action: "list", id: densityInstance.id)
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'density.label', default: 'Density'), params.id])}"
            redirect(action: "list")
        }
    }

The Rcommodity is the name of the textfields created, I put a println to see if the value was right, now I don't know how to make the value of the textfield be the one entered, it gives me the same value it had before but it gives me the message saying that it was updated. The controller is DensityController and the domain is density

Any help would be greatly appreciated. Thanks :D


Looks from the flash message being printed as though the instance is being updated (though the "#ID" bit looks odd - have you replaced the actual id?).

It might be that

densityInstance.properties = params

is not actually be matching any instance properties, so none are actually being changed before the save. Are you sure you've named your gsp input fields to match the names of your Density class fields? Is Rcommodity a property of Density, for example?

Might help to add the form bit of your gsp page, as well as the Density domain class.

0

精彩评论

暂无评论...
验证码 换一张
取 消