D.Sanxhez
D.Sanxhez

Reputation: 137

Passing parameters from one method to another in my controller

Save parameters of a method to another.

Save parameters of the person in my def contentPerson in my method saveperson. Does anyone know how to save parameters - no found of my method savework

def saveperson(Person personIntance) {
    def contentPerson =personInstance.save(flush:true)
     redirect(controller:'Person', action:'creatework')
      flash.message="I automatically select the person id";
}

def savework(Work workInstance,contentPerson) {
    def work1 = new Work(name:params.name,person:contentPerson, profession:params.profession)
    work1.save(flush:true)
}

Message:

No such property: contentPerson

Upvotes: 1

Views: 2131

Answers (1)

Sachin
Sachin

Reputation: 1218

redirect makes a completely new call, so it is a completely different context. you might want to try this:

redirect(controller:'Person', action:'creatework', params:[contentPerson: contentPerson])

or save it in flash, like this:

flash.contentPerson = contentPerson

you can use it for another request, like this:

flash.contentPerson

but you should avoid flash messages. so better pass parameters.

Upvotes: 2

Related Questions