Migration to CUBA 7 API: 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

The window element

In your screen’s XML file, change the value of the window’s xmlns attribute from

<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
...

to

<window xmlns="http://schemas.haulmont.com/cuba/screen/window.xsd"
...

Once the value of the xmlns attribute is changed, all legacy attributes and elements are marked in red, i.e. unavailable for use.

image

Remove obsolete attributes of the <window> element.

Data Sources

Replace <dsContext> with <data>, e.g collectionDatasource must be replaced with collection container:

Before

<dsContext>
    <collectionDatasourceid="productsDs"
                     class="com.company.sales.entity.Product"
                     view="_local">
        <query>
            <![CDATA[select e from sales$Product e]]>
        </query>
    </collectionDatasource>
</dsContext>

After

<data readOnly="true">
    <collection id="productsDc"
                class="com.company.sales.entity.Product"
                view="_local">
        <loader id="productsDl">
            <query>
                <![CDATA[select e from sales$Product e]]>
            </query>
        </loader>
    </collection>
</data>

Replace datasource / optionsDatasource attributes with dataContainer / optionsContainer.

Before

<lookupField optionsDatasource="productsDs"/>

After

<lookupField optionsContainer="productsDc"/>

Note: for the <table> element the dataContainer attribute must be defined for the <table> element itself instead of the nested <rows> element.

Actions

A standard action can be declared in screen XML descriptor by specifying its type in the type attribute, i.e. the id attribute is optional and no longer defines action type.

Add the type attribute with a proper value for all actions, e.g.

Before

<!-- in a table -->
<actions>
    <action id="create"/>
    <action id="edit"/>
    <action id="remove"/>
</actions>
<!-- in a PickerField -->
<actions>
    <action id="lookup"/>
    <action id="clear"/>
</actions>

After

<!-- in a table -->
<actions>
    <action id="create" type="create"/>
    <action id="edit" type="edit"/>
    <action id="remove" type="remove"/>
</actions>
<!-- in a PickerField -->
<actions>
    <action id="lookup" type="picker_lookup"/>
    <action id="clear" type="picker_clear"/>
</actions>

Screen registration

Remove the old screen definition from screens.xml / web-screens.xml

Controller migration

  • Extend the com.haulmont.cuba.gui.screen.Screen class instead of com.haulmont.cuba.gui.components.AbstractWindow.
  • Define the @UiController annotation with the screen id, e.g. @UiController("sales_Product.browse").
  • Define the @UiDescriptor annotation with the screen descriptor path (either relative or full), e.g. @UiDescriptor("product-browse.xml").
  • (Optional) Add the @LoadDataBeforeShow annotation in order to indicate that all data loaders should be triggered automatically before showing the screen.

Lifecycle methods

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

init

Before

@Override
public void init(Map<String, Object> params) {
    ...
}

After

@Subscribe
private void onInit(InitEvent event) {
    ...
}

ready

Before

@Override
public void ready() {
    ...
}

After

@Subscribe
private void onAfterShow(AfterShowEvent event) {
    ....
}

preClose

Before

@Override
protected boolean preClose(String actionId) {
    return super.preClose(actionId);
}

After

@Subscribe
private void onBeforeClose(BeforeCloseEvent event) {
    ....
}

close

Before

@Override
public boolean close(String actionId) {
    return super.close(actionId);
}

After

@Subscribe
private void onAfterClose(AfterCloseEvent event) {
    ...
}

Window API

In order to get access to the Window API, e.g. setCaption(), add(Component) etc. obtain the Window object using the getWindow() method.

@Subscribe
protected void onInit(InitEvent event) {
    ...

    getWindow().add(button);
}

Opening Screens

openWindow(), openEditor(), openLookup() and openFrame() methods are no longer available in the new screens API.

For the full information see the doc.

Notifications

The showNotification methods are no longer available in the new screens API.

In order to show a notification, inject the Notifications bean into the screen controller and use its fluent interface, e.g.

@Inject
private Notifications notifications;

@Subscribe("sayHelloBtn")
protected void onSayHelloBtnClick(Button.ClickEvent event) {
    notifications.create().withCaption("Hello!").show();
}

For the full information see the doc.

Dialogs

The showMessageDialog() and showOptionDialog() methods are no longer available in the new screens API.

In order to show a notification, inject the Dialogs bean into the screen controller and use its fluent interface, e.g.

@Inject
private Dialogs dialogs;

@Subscribe("showDialogBtn")
protected void onShowDialogBtnClick(Button.ClickEvent event) {
    dialogs.createMessageDialog().withCaption("Information").withMessage("Message").show();
}

For the full information see the doc.

4 Likes