TreeDataGrid not creating child record

Hi,

I’m using Cuba 7.2.6.

I’m using TreeDataGrid in many places of my application. But the create actions doesn’t work properly for TreeDataGrid. When user selects a record and tries to create a child record of that record using the Create action, it doesn’t work creates the parent child relationship instead it creates as if a new record.

I found below code in Create Action which is responsible for set the parent/child relationship but the if condition is failing while checking whether the TreeDataGrid is instance of Tree.

image

How do I fix this?

Thanks,
Hari

Hi @harikrishnadhas.k1,

You can set the parent field of new entities implementing a initializer or newEntitySupplier (see CreateAction).

Inject the treeDataGrid in your controller and supply the parent field value using the method getSingleSelected(). Something like that:

@Install(to = "treeDataGrid.create", subject = "initializer")
private void treeDataGridCreateInitializer(Entity entity) {
	entity.setParentField(treeDataGrid.getSingleSelected());
}

Regards,
Peterson.

Hi @peterson.br,

I know these tricks, but would like to check if it will work out of the box and some bug is there.

Thanks,
Hari

Hi,

The code that you’re pointing is in the legacy CreateAction (com.haulmont.cuba.gui.components.actions.CreateAction) that is used in legacy screen, i.e. CUBA 6 screens. Since you’re using CUBA 7, the preferable way is using CreateInitializer as shown by @harikrishnadhas.k1. Even though it requires additional code from a developer, this approach is more flexible. In case, you need such functionality in several screens, I’d recommend implementing a custom action that sets a parent if possible.

Regards,
Gleb

Thanks @gorelov. will implement the same.