Closed vlipovetskii closed 3 years ago
First of all, my congratulations ! Karibu-dsl became "official" part of Vaadin kotlin support.
Thank you so much :+1: :-)
raises error about duplicating BeanPropertry. I have not investigated yet, why beanProperty is treaated as duplicated. Maybe it's java/kotlin collision.
Interesting, it also sounds to me like like there could be a java/kotlin collision. Could you please paste a stack trace of the exception? It would be really good to have this documented, in case we revert back to using the parameterless Grid constructor.
Is it acceptable to have in karibu-dsl two grid/treeGrid methods, which use different constructors (default and with BeanProperty support) ?
That would be acceptable (or even better, the grid()
function could have a parameter, something like 'passItemClass` defaulting to true. However, before we jump to this solution, could we perhaps try to solve the "duplicated bean property" issue? It would be really good to have this documented.
Just to document why the change was made: having the item class will allow us two things:
However, both use-cases are not really that important:
addColumnFor(KProperty)
anyway, to benefit from a type-safe system.So, all in all, I'm open to reverting the Grid construction code back to zero-arg constructor; but first I wonder whether we can do something about that duplicated bean property.
I have tried to migrate my project to investigate the issue. Unfortunately, a new issue appeared. I have a generic class with generic parameter for Grid Row. New grid and treeGrid functions leverage reified generic parameter, and thus my class can't be leveraged with the new grid and treeGrid. I don't leverage Binder. I will create (temporarily) in my code, copies of your grid/treeGrid functions (see fragment below) without reified and with default constructor to migrate to karibu-dsl 1.x.
BTW, Why not to have two implementations of grid/treeGrid (your new implementations and functions like below, but with more pretty names) ?
@VaadinDsl
fun <T : Any?> (@VaadinDsl HasComponents).grid1(dataProvider: DataProvider<T, *>? = null, block: (@VaadinDsl Grid<T>).() -> Unit = {}) =
init(Grid<T>()) {
if (dataProvider != null) this.dataProvider = dataProvider
block()
}
@VaadinDsl
fun <T : Any?> (@VaadinDsl HasComponents).treeGrid1(dataProvider: HierarchicalDataProvider<T, SerializablePredicate<T>>? = null, block: (@VaadinDsl TreeGrid<T>).() -> Unit = {}) =
init(TreeGrid<T>()) {
if (dataProvider != null) this.dataProvider = dataProvider
block()
}
BTW, Why not to have two implementations of grid/treeGrid (your new implementations and functions like below, but with more pretty names) ?
I so far have failed to come up with a proper naming with the alternate functions. The problem is that the advantages of passing the item Class to Grid are very minor; I fail to see the major differentiator which could then be used in the function name.
Because of that, I'm actually toying with the idea of reverting the code back to use the zero-arg constructor (or having additional parameter in the grid function). However, first I'd like to get to the bottom of that duplicate BeanProperty issue. Could you please paste a stacktrace here, just for the documentation purposes?
I have a generic class with generic parameter for Grid Row. New grid and treeGrid functions leverage reified generic parameter, and thus my class can't be leveraged with the new grid and treeGrid.
Oh - I've missed this important piece. Actually this works for me: the following code compiles happily with Kotlin 1.4.0:
data class TestingClass<T>(var item: T? = null)
UI.getCurrent().grid<TestingClass<String>>()
Regarding the duplicite bean property: this PR sounds like it fixes that very issue in Vaadin 8: https://github.com/vaadin/framework/pull/12091
Perhaps we should introduce a similar PR into Vaadin 14 as well.
By fixing #28 I've realized that, by using those new functions, we will be able to pass in null class as follows:
UI.getCurrent().grid<Person>(klass = null)
or
UI.getCurrent().grid<Person>(clazz = null)
@vlipovetskii what do you think? Would this work for you please?
Yes, if to pass null and leverage Grid constructor without beanType parameter in the case of null ?
Yup, that's exactly the idea. I'll add a docu regarding this shortly.
Please see https://github.com/mvysny/karibu-dsl/tree/master/karibu-dsl#grid for more details; the code is merged in Karibu-DSL master (but hasn't been released yet).
First of all, my congratulations ! Karibu-dsl became "official" part of Vaadin kotlin support.
I tried to migrate my projects from 0.7.5 to 1.0.2 and met the error about duplicating of a bean property in BeanPropertySet.java.
Before Grid.kt leveraged default constructor of Grid in Grid.java
init(Grid<T>()) {
Now Grid.kt leverages another constructorval grid = Grid<T>(T::class.java, false)
The effective difference in code of the constructors isWhen one of my grids is created, the method
raises error about duplicating BeanPropertry. I have not investigated yet, why beanProperty is treaated as duplicated. Maybe it's java/kotlin collision.
As a workaround: Is it acceptable to have in karibu-dsl two grid/treeGrid methods, which use different constructors (default and with BeanProperty support) ?
If no, I will do the methds with default constructor as part of my code.