I’m using grails 1.3.7.
I have the following Domain:
class Category {
String name;
String categoryKey;
Date dateCreated
Date lastUpdated
static constraints = {
name(blank: false, nullable: false, maxSize:30)
categoryKey(blank: false, nullable: false, maxSize:30)
}
String toString()
{
return name
}
}
I display the list of categories in gsp as follows:
<g:select class="fields" valueMessagePrefix="shared.category.label" name='categoryKey'
value="${dealInstance?.category?.categoryKey}"
noSelection="${['': message(code: 'layouts.main.filter.select', default: '(Please select one)')]}"
from='${categoryList.list()}' optionValue="name"
optionKey="categoryKey"></g:select>
I need to display the list with one of it’s items removed (Where categoryKey property equals OTHER).
def Category categoryList = Category
//categoryList.categoryKey.remove("OTHER") How to remove here maybe?
return [dealInstance: dealDetails, categoryList: categoryList ]
How can I remove this in my controller and pass the new list (Minus OTHER) to the gsp?
Thanks
You can use the findAll collection function and use the closure to check for the object you want to remove.
From the documentation:
So you can do something like:
You can also use this oneliner directly in your view if you like.