alejandro-du / crudui

Automatically generate CRUD-like Vaadin views for any Java Bean
https://vaadin.com/directory#!addon/crud-ui-add-on
Apache License 2.0
86 stars 54 forks source link

this.domainType.newInstance(); Does not work with not public constructor. #67

Closed drswaki69 closed 4 years ago

drswaki69 commented 4 years ago

https://github.com/alejandro-du/crudui/blob/9cf20e1dde4e79058b72d9203a8e39a0725dabf0/add-on/src/main/java/org/vaadin/crudui/crud/impl/GridCrud.java#L168

T domainObject = this.domainType.newInstance(); Does not work with not public constructor.

Which is common with JPA, because default constructor is needed but not wanted.

3 possible Options;

  1. Give the GridCrud an option to provide a new instance supplier. protected void addNewInstanceSupplier(Supplier supplier){ return this.supplier; }

T domainObject = this.supplier.get(); // default supplier can still be this.domainType.newInstance();

  1. Make a method that provides a new instance that can be overridden protected T createdNewInstance(){ T domainObject = this.domainType.newInstance(); } // gives people the change to use a builder or just construct an object.

  2. use reflection to make it accessible, when it's not accessible.

drswaki69 commented 4 years ago

Nice!