closures - reuse Criteria in Grails Controller -
typically have following last line in grails generated controller list method:
[userinstancelist: user.list(params), userinstancetotal: user.count()]
if want restrict users specific criteria looks like
[userinstancelist: user.list(params) { ilike('login', '%test%') }, userinstancetotal: user.count() { ilike('login', '%test%') }]
but violates dry principle - best way reuse criteria closure?
paged results criteria builder (the result class pagedresultlist) have property, totalcount
, can use calling count()
on same criteria:
def userinstancelist = user.createcriteria().list(params) { ilike 'login', '%test%' } [userinstancelist: userinstancelist, userinstancetotal: userinstancelist.totalcount]
Comments
Post a Comment