Search code examples
grailsgsp

get the value sent with g:link on GSP


<li><g:link params="[num: patientInstance.id]" controller="Consultation" action="create">creer consultation </g:link></li>

this g:link is in the patient view\show , i use it to send the id of the patient to the consultation controller in order to use it later ,so how can i get the patientInstance.id in consultation controller ?

thanks for your answers.


Solution

  • You use the params map.
    http://grails.org/doc/latest/ref/Controllers/params.html

    So in your Consultation controller you have your create action as such:

    def create() {
        def patient = Patient.get(params.num.toLong())
    ...//do something else //
    
    }
    

    Then you have it render a view, or send a map back to the gsp with the name create.