Migration to CUBA 7 API: Editor Screens

Please note that your entire codebase should work on the new version of the framework only with minor changes listed in the release notes, i.e. you don’t need to migrate existing screens on the new API, but if you want, the following guide may be helpful.

Table of Contents

Migration to CUBA 7 API: Screens
Migration to CUBA 7 API: Browser / Lookup Screens
Migration to CUBA 7 API: Editor Screens
Migration to CUBA 7 API: Required Components Migration
Migration to CUBA 7 API: Optional Components Migration

XML descriptor migration

Please read the previous sections before continuing with this.

The window element

In addition to the other legacy attributes, remove the datasource attribute of the <window> element.

Data Sources

As mentioned above, replace <dsContext> with <data>, e.g.

Before

<dsContext>
    <datasource id="productDs"
                class="com.company.sales.entity.Product"
                view="_local"/>
</dsContext>

After

<data>
    <instance id="productDc"
              class="com.company.sales.entity.Product"
              view="_local">
        <loader id="productDl"/>
    </instance>
</data>

The main editor component

Replace FieldGroup with Form, e.g.

Before

<fieldGroup id="fieldGroup"
            datasource="productDs">
    <column width="250px">
        <field property="name"/>
        <field property="price"/>
    </column>
</fieldGroup>

After

<form id="form"
      dataContainer="productDc">
    <column width="250px">
        <textField id="nameField"
                   property="name"/>
        <textField id="priceField"
                   property="price"/>
    </column>
</form>

There is a handy live template in Studio: field which will generate corresponding field component as soon as property specified.

If border was enabled in <fieldGroup> you will need to wrap <form> by <groupBox> (and move caption to the latter) to achieve the same layout.

Editor Actions

Replace the editWindowActions frame with hbox that contains buttons with corresponding actions, e.g.

Before

<frame id="windowActions"
       screen="editWindowActions"/>

After

<hbox id="editActions"
      spacing="true">
    <button action="windowCommitAndClose"/>
    <button action="windowClose"/>
</hbox>

Consequently, the <layout> element must extend editActions instead of windowActions.

Controller migration

  • Extend the com.haulmont.cuba.gui.screen.StandardEditor class instead of com.haulmont.cuba.gui.components.AbstractEditor.
  • Define the @EditedEntityContainer annotation with a data container that contains edited entity., e.g. @EditedEntityContainer("productDc").

Minimal editor implementation

@UiController("sales_Product.edit")
@UiDescriptor("product-edit.xml")
@EditedEntityContainer("productDc")
@LoadDataBeforeShow
public class ProductEdit extends StandardEditor<Product> {
}

Lifecycle methods

All legacy lifecycle methods can be replaced with Screen Controller Events.

initNewItem

Before

@Override
protected void initNewItem(Product item) {
    ...
}

After

@Subscribe
private void onInitEntity(InitEntityEvent<Product> event) {
    ...
}

postInit

Before

@Override
protected void postInit() {
    ...
}

After

@Subscribe
private void onAfterInit(AfterInitEvent event) {
    ...
}

preCommit

Before

@Override
protected boolean preCommit() {
    ...
    return super.preCommit();
}

After

@Subscribe
private void onBeforeCommitChanges(BeforeCommitChangesEvent event) {
    ...
}

postCommit

Before

@Override
protected boolean postCommit(boolean committed, boolean close) {
    ...
    return super.postCommit(committed, close);
}

After

@Subscribe
private void onAfterCommitChanges(AfterCommitChangesEvent event) {
    ...
}

postValidate

Before

@Override
protected void postValidate(ValidationErrors errors) {
    errors.add("Some error");
}

After

@Override
protected void validateAdditionalRules(ValidationErrors errors) {
    errors.add("Some error");
    super.validateAdditionalRules(errors);
}
6 Likes