gpc / fields

a spiritual successor to the bean-fields plugin
http://gpc.github.io/fields/
84 stars 106 forks source link

Populations of abstract classes are not listed in index #307

Closed amador-duran-toro closed 4 years ago

amador-duran-toro commented 4 years ago

In Grails 4.0.3 and Grails 3.3.11, if you have an inheritance hierarchy with an abstract superclass, e.g.

package mypackage

abstract class A {
  String name
  // ...
  // properties
  // ...
}
package mypackage

class B extends A {
  String b
  // ...
  // properties
  // ...
}
package mypackage

class C extends A {
  String c
  // ...
  // properties
  // ...
}

And you populate the concrete classes in Bootstrap.groovy, e.g.

package mypackage

class BootStrap {

    def init = { servletContext ->
        A.withTransaction { status ->
            def listOfB = []
            (1..25).each { i ->
                listOfB << new B(name:"b${i}",b:"${i}st")
            }

            B.saveAll( listOfB )

            def listOfC = []
            (1..25).each { i ->
                listOfC << new C(name:"c${i}",c:"${i}nd")
            }

            C.saveAll( listOfC )
        }
    }
    def destroy = {
    }
}

If you use scaffolding, the index page for A shows an empty list instead of a paginated list of 50 objects (25 B objects and other 25 C objects).

Apart from that, it shows a new button that generates a java.lang.InstantiationException when clicked because it tries to instantiate an abstract class.

The workaround for this problem is the following:

  1. Generate views for the abstract class (only index.gsp is relevant)
  2. Edit the generated index.gsp in the following way:

With respect to <f:table> attributes:

Apart from that, the create and edit pages are still available for A. I have generated-all for A and tried to delete those methods from the generated controller, but my knowledge of Grails is limited and I am having lots of errors with that, so I went back to scaffolding (which is my main reason for using Grails).

I think that Grails should not show empty lists for abstract classes in scaffolding, but I do not know if that behaviour is inside the scaffolding controller, the <f:table> tag, or harcoded in _table.gsp.

I also think that Grails should not generate create and update methods in the scaffolding controllers for abstract classes.

osscontributor commented 4 years ago

This is better suited for https://github.com/grails3-plugins/scaffolding/issues. It isn't really a fields plugin issue.

amador-duran-toro commented 4 years ago

This is better suited for https://github.com/grails3-plugins/scaffolding/issues. It isn't really a fields plugin issue.

You are right. I have posted it in https://github.com/grails3-plugins/scaffolding/issues/43.

Shoud I close this issue?

sbglasius commented 4 years ago

As written, not a Fields Plugin Issue