Initialize entity before create?

When I am on a list view and click the Create button I need to pre-populate some of the entity fields before it is displayed to the user. This was working in Jmix 1.5, but does not work the same way in Jmix 2.

Can someone provide the way or point to an example?

Thanks!

Hello,

Which way did you pre-populate the entity, in the controller or using Lifecycle Callbacks?
It would be great if you could send an example of your method.

Regards,
Nikita

I am trying to pre-populate from the view controller. This is the Jmix 2 version of the same approach that worked in 1.5:

    @Install(to = "memberDataGrid.create", subject = "initializer")
    private void memberDataGridCreateInitializer(final Member member) {
        Integer max = dataManager.loadValue("select max(m.memberNumber) from Member m", Integer.class).one();
        member.setMemberNumber(max + 1);
    }

I also tried the newEntitySupplier handler, also with no success. Both methods were created in Studio by adding a handler on the Create action. In both cases a break point in the method was never hit, so it seems the event was never triggered. The list view is a standard one created by Studio.

By the way, the string “newEntitySupplier” does not appear in the documentation.

There is such a problem. Will be fixed in future releases.

You can initialize an entity in StandardDetailView using onInitEntity.