0
votes

I have this button:

<button id = "select"
            onclick = "<g:remoteFunction controller='customer' action='selectBatch'/>"
            params: '\'batchID=\' + selectedBatchID'>Select</button>

which does call this method in my controller:

def selectBatch = {
    println "Batch Selected: " + params.batchID
}

but with this output:

Batch Selected: null

Here is the related javascript that generates and prepares the variable to be passed in the params:

var table = document.getElementById('batchTble'),
rows = table.getElementsByTagName('tr');
var selectedBatchID;

for (var i=0,len=rows.length; i<len; i++){
rows[i].onclick = function(){
    console.log(this.cells[0].innerHTML);
    selectedBatchID = parseInt(this.cells[0].innerHTML);
    console.log(selectedBatchID)
    /* if you know it's going to be numeric:
    console.log(parseInt(this.innerHTML),10);
    */
}

I did confirm that the javascript variable "selectedBatchID" does print to the console so it does indeed hold a value. But the value never makes it into the params that the controller gets for some reason. Here is what the Chrome debug console give me at the same time as the controller complains about null:

17 VM3216:53
POST http://ec2-54-209-146-139.compute-1.amazonaws.com:8080/FatcaOne_0/customer/selectBatch 404 (Not Found) jquery.tools.min.js:38
send jquery.tools.min.js:38
onclick

You can see that the value '17' printed in the Chrome debug console but never makes it into the controller as params.batchID. Why my param is null and I get the 404 not found is what I do not understand? Any help appreciated. I'd be happy to provide more details on request.

1

1 Answers

1
votes

onclick looks incorrect. Refer docs for details. Based on that it should be something like:

<button id = "select"
        onclick = "${remoteFunction(controller: 'customer', 
                                    action: 'selectBatch',
                                    params: '\'batchID=\' + selectedBatchID')}">
Select
</button>

I suppose you have mixed the taglib and method call syntax as shown in the question (usage of key-value for params versus attributes for action and controller). Moreover, params is not part of remoteFunction altogether in the question.