amador-duran-toro opened a new issue, #14218:
URL: https://github.com/apache/grails-core/issues/14218

   In Grails 4.0.3 and Grails 3.3.11, when a class has a collection of enums as 
a field, e.g.
   
   ```{groovy}
   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
   }
   ```
   
   Or as a _hasMany_ association, e.g.
   
   ```{groovy}
   package mypackage
   
   class MyClass {
     String name
     // ...
     // properties
     // ...
   
     static hasMany = [enums:MyEnum]
   }
   
   enum MyEnum {
     ENUM_VALUE_1,
     ENUM_VALUE_2,
     ENUM_VALUE_3
   }
   ```
   
   And you populate the class in `Bootstrap.groovy`, e.g.
   
   ```{groovy}
   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:
   
   ```{html}
   <g:select 
       multiple="true" 
       name="${property}" 
       from="${mypackage.MyEnum}"
       value="${myClass?.enums}"
   />
   ```
   
   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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to