I have this code in a custom taglib that calls the GrailsUI Autocomplete tag:
def renderAutoComplete(uicName,isDisabled,theValue) {
params.tableId = 3 // THIS ISN'T AVAILABLE TO AUTO COMPLETE ACTION
out << gui.autoComplete(id:uicName,resultName:"lookUpData",controller:"lookupTable",action:"autoCompleteJSON") {}
}
Here's my action that get's called to populate the autocomplete:
def autoCompleteJSON = {
def lookupTable = LookupTable.get(3) // PARAM NEEDS TO BE SET IN TAGLIB
def list = LookupValue.findAllByLookupTableAndThevalueLike(lookupTable,"${params.query}%")
def jsonList = list.collect { [ id: it.id, name: it.thevalue ] }
def jsonResult = [
lookUpData: jsonList
]
render jsonResult as JSON //render only works in a controller
}
Everything works fine using the hard coded:
def lookupTable = LookupTable.get(3)
but of what I need is:
def lookupTable = LookupTable.get(params.tableId)
and params.tableId isn't available to the auto complete.
So how can I set a param in a taglib?
UPDATE
It turns out that gui.autocomplete provides two more params that I wasn't aware of. filterBy and filter can be used for precisely the need of passing a filter param to your controller. So now I do:
out << gui.autoComplete(id:uicName,resultName:"lookUpData",controller:"lookupTable",action:"autoCompleteJSON",filterBy:"lookupTable",filter:"${theTagtype.lookupTable.id}", queryDelay:"0.5", value:"${theValue}") {}
and it works perfectly. So my immediate problem is solved. But the general question remains: How can I set a param in a taglib?