[英]Grails: pass a List from GSP to controller with remote link
So, in my method A in the controller ServicioComunitario I send this to the GSP: 因此,在控制器ServicioComunitario的方法A中,将其发送到GSP:
tg = ServicioComunitario.findAll("from ServicioComunitario as b where "+query)
[servicioComunitarioInstanceList: tg, params: params]
Then in the GSP I call another method (generarDocDeReporte) of ServicioComunitarioController: 然后在GSP中,我调用ServicioComunitarioController的另一个方法(generarDocDeReporte):
<g:set var="b" value="${'xls'}"/>
<g:set var="a" value="${'excel'}"/>
<g:set var="servicioLista" value="${servicioComunitarioInstanceList}"/>
<g:link controller="ServicioComunitario" action="generarDocDeReporte"
params="${[exportFormat:a, extesion:b, tg: servicioLista] }"
update="mainContent">Excel</g:link><br/>
Then, in the new method "generarDocDeReporte" I have: 然后,在新方法“ generarDocDeReporte”中,我有:
println params.exportFormat+"-"+params.extesion
if(params.tg)
println "Not empty"
exportFormat and extension work as expected, but the params.tg doesn't seem to behave normal. exportFormat和扩展名可以正常工作,但是params.tg似乎不正常。
I am trying to use this new params.tg where it was a ServicioComunitario.list(params): 我试图在ServicioComunitario.list(params)使用这个新的params.tg:
exportService.export(params.exportFormat, response.outputStream, ServicioComunitario.list(params), fields, labels, formatters, parameters)
And here is where I get the error: 这是我得到错误的地方:
exportService.export(params.exportFormat, response.outputStream, params.tg, fields, labels, formatters, parameters)
When I receive the params.tg, do I need to cast it? 收到params.tg时,是否需要强制转换? or what do you think is the error?
还是您认为错误是什么?
Thank you very much in advance 提前非常感谢你
You can't just pass a list of instances like that in a link. 您不能仅在链接中传递类似的实例列表。 You can however collect the ids into a list as a parameter and then use it to populate it later.
但是,您可以将ID作为参数收集到列表中,然后在以后使用它进行填充。 For example:
例如:
<g:link controller="ServicioComunitario" action="generarDocDeReporte"
params="${[exportFormat:a, extesion:b, tgids: servicioLista.collect{it.id}.join(',')] }"
update="mainContent">Excel</g:link><br/>
And then in your controller where you need to get the list again: 然后在控制器中,您需要再次获取列表:
def tg = ServicioComunitario.getAll(params?.tgids?.tokenize(","))
Also, you don't need to assign params
to params
when returning your model. 此外,您不需要分配
params
到params
返回你的模型时。 parameters are already exposed in the GSP by convention. 按照惯例,参数已在GSP中公开。
[servicioComunitarioInstanceList: tg]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.