You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Grails 4.0.3 and Grails 3.3.11, when a class has a collection of enums as a field, e.g.
package mypackage
class MyClass {
String name
// ...
// properties
// ...
Set<MyEnum> enums
// no need to declare it as embedded
// but you can do it if you like
// static embedded = ['enums']
}
enum MyEnum {
ENUM_VALUE_1,
ENUM_VALUE_2,
ENUM_VALUE_3
}
And you populate the class in Bootstrap.groovy, e.g.
package mypackage
class BootStrap {
def init = { servletContext ->
MyClass.withTransaction{ status ->
MyClass.saveAll(
new MyClass(name:"c1").addToEnums(MyEnum.ENUM_VALUE_1),
new MyClass(name:"c2").addToEnums(MyEnum.ENUM_VALUE_2),
new MyClass(name:"c3").addToEnums(MyEnum.ENUM_VALUE_3)
)
}
}
def destroy = {
}
}
If you use scaffolding, the content of the enum collection is shown in the index and show pages, but not in the edit and create pages, where only the label is shown, no widget is displayed for the field.
If you generate the views for the class, the fields are displayed using <f:all bean="myClass"/>.
There is a workaround for this problem, without having to generate the views, which is creating the grails-app/views/_fields/myClass/enums/_widget.gsp file with the following content:
I think that this should be the default behaviour for collections of enums in scaffolding, but I do not know how to implement it using the fields plugin for any collection of enums instead of for a given field only.
The text was updated successfully, but these errors were encountered:
In Grails 4.0.3 and Grails 3.3.11, when a class has a collection of enums as a field, e.g.
Or as a hasMany association, e.g.
And you populate the class in
Bootstrap.groovy
, e.g.If you use scaffolding, the content of the enum collection is shown in the index and show pages, but not in the edit and create pages, where only the label is shown, no widget is displayed for the field.
If you generate the views for the class, the fields are displayed using
<f:all bean="myClass"/>
.There is a workaround for this problem, without having to generate the views, which is creating the
grails-app/views/_fields/myClass/enums/_widget.gsp
file with the following content:I think that this should be the default behaviour for collections of enums in scaffolding, but I do not know how to implement it using the fields plugin for any collection of enums instead of for a given field only.
The text was updated successfully, but these errors were encountered: