Problem with DataContainer

Hi All

Attached you find a simple application

  • address entity with 1:M composition of many contacts
    dcTwo.zip (110.2 KB)

In address-detail-view i want to display all contacts of this address sorted by date.

I made a collection

		<collection id="contactDc2" class="com.company.dctwo.entity.Contact">
			<fetchPlan extends="_base">
				<property name="adres" fetchPlan="_base"/>
			</fetchPlan>
			<loader>
				<query>
					<![CDATA[select e from Contact e where e.adres.id = :component_id order by e.date desc]]>
				</query>
			</loader>
		</collection>

Everything is working fine, except when I want to create a new contact !

The

<entityPicker id="adresField" property="adres">

in contact-detail-view does not get populated anymore …

What do I miss ?

Thank you for any hints :wink:

Best regards
Felix

Hi All

I have the feeling this is a bug or something which can be solved easily; am I wrong ?

Best regards
Felix

Hello Felix,

It is not a bug. When you change collection container from nested to a separate, the detail dialog builder loses information about composition and cannot init new entity by adres property.

As ContactDetailView is opened as dialog, you can set newEntitySupplier to CreateAction. For instance:

@Autowired
private Metadata metadata;

@Install(to = "contactDataGrid.createAction", subject = "newEntitySupplier")
private Contact contactDataGridCreateActionNewEntitySupplier() {
    Contact contact = metadata.create(Contact.class);
    contact.setAdres(getEditedEntity());
    return contact;
}
2 Likes

Thank you a lot for your explanation !

After you mention the nested collection, I remembered someting in the documentation I found https://docs.jmix.io/jmix/tutorial/data-in-ui.html#order-nested-collection about nested collections and did adapt this :wink:

You cannot imagine, how some little hints like this one save a day !

1 Like