Reputation: 3401
Im trying to get how many is in my list and convert it to string. So that i can show in my gsp how many is in the list. However when i call it, it is null. Although, there when i print it in the console it shows it's actual value
def menuItem(Integer max, String category) {
def categoryList, menuItem
if(category){
categoryList = MenuItemCategory.findByName(category)
menuItem = categoryList ? MenuItem.findAllByMenuItemCategory(categoryList) : []
}
else{
params.max = Math.max(max ?: MenuItem.count(), 1)
menuItem = MenuItem.list(params)
}
def count = menuItem.size().toString()
println count
[menuItemInstanceList: menuItem, allCount: count]
}
using ${allCount}
in my gsp gives me null
Upvotes: 0
Views: 153
Reputation: 50245
Domain.list(max)
will return a PagedResultList
, which has getTotalCount()
which can be used to find the total count.
in above case:
${ menuItemInstanceList.size() } //actual count using pagination
${ menuItemInstanceList.totalCount } //total count
Upvotes: 3