KeyValueContainer and edit action

Hi,

I’ve created a KeyValueContainer attached to some DataGrid. All data are read and displayed fine.

Now I want to edit some record. When I push edit button, application sends me “KeyValueEntity.edit” screen doesn’t exists. OK, I agree. Please tell me: how does I link record in datagrid with editor screen ?

Stef.

PS: KeyValue management is not so well documented …

1 Like

Hello,

to open the editor for your entity in the KeyValueContainer you should load additional property that can be used for relation your entity and editor, for instance, entity’s id or even the whole entity:

keyValueCollection
<data readOnly="true">
    <keyValueCollection id="customersDc">
        <loader id="customersDl">
            <query>
                <![CDATA[select e, e.id, e.name from demo_Customer e]]>
            </query>
        </loader>
        <properties>
            <property name="customer" class="com.company.demo.entity.Customer"/>
            <property name="customerId" datatype="uuid"/>
            <property name="customerName" datatype="string"/>
        </properties>
    </keyValueCollection>
</data>

Then just override Edit action in the controller and open editor:

Controller code
@Inject
private GroupTable<KeyValueEntity> customersTable;
@Inject
private ScreenBuilders screenBuilders;

@Subscribe("customersTable.edit")
public void onCustomersTableEdit(Action.ActionPerformedEvent event) {
    KeyValueEntity entity = customersTable.getSingleSelected();

    screenBuilders.editor(Customer.class, this)
            .editEntity(entity.getValue("customer"))
            .show();
}

In the case of id, you should send it as a screen parameter to the editor and then load an entity by its id.

I have created an issue to improve KeyValueContainer documentation: issue.

Thank you very much. :wink: