OpenType.DIALOG in v 7

In the legacy version of the platform we could select the OpenType of the Editor from the table event designer without writing any code but I don’t see it anymore.

image

Do we need to code it under @Subscribe in the controller? Thanks for guiding to the right process CUBA being a RAD tool!

Hi,

for the new API you need to subscribe on ActionPerformedEvent and provide a custom implementation, e.g.

@UiController("sales_Product.browse")
@UiDescriptor("product-browse.xml")
@LookupComponent("productsTable")
@LoadDataBeforeShow
public class ProductBrowse extends StandardLookup<Product> {
    @Inject
    private GroupTable<Product> productsTable;

    @Inject
    private ScreenBuilders screenBuilders;

    @Subscribe("productsTable.create")
    private void onProductsTableCreate(Action.ActionPerformedEvent event) {
        screenBuilders.editor(Product.class, this)
                .newEntity()
                .withLaunchMode(OpenMode.DIALOG)
                .build()
                .show();
    }

    @Subscribe("productsTable.edit")
    private void onProductsTableEdit(Action.ActionPerformedEvent event) {
        screenBuilders.editor(productsTable)
                .withLaunchMode(OpenMode.DIALOG)
                .build()
                .show();
    }
}

You can read more about opening screens in the doc.

Gleb

The easiest way is to set forceDialog="true" for the <dialogMode/> element of an editor screen.

...
<dialogMode height="600" 
            width="800"
            forceDialog="true"/>
...
1 Like

Thanks Gleb.

The difference is, in V6x only selection of openMode in the screen builder used to do all it needs. Now the lines of codes to open the screen making the platform moving away a bit from a RAD tool and this is only an example (there are many more such example I am coming across). I hope this is not how it is planned but matter of time to get those RAD functionalities back in V7 soon.

1 Like

Hi,

The third possible approach is to implement custom Create/Edit actions that can be used independently of the standard ones.

Take a look at the demo project that illustrates the above dialog-actions.zip (81.7 KB).

DialogCreateAction and DialogEditAction are custom actions and both are used in the product-browse.xml:

@ActionType(DialogCreateAction.ID)
public class DialogCreateAction extends CreateAction {

    public static final String ID = "create_dialog";

    public DialogCreateAction() {
        this(ID);
    }

    public DialogCreateAction(String id) {
        super(id);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void actionPerform(Component component) {
        // if standard behaviour
        if (!hasSubscriptions(ActionPerformedEvent.class)) {
            Screen editor = screenBuilders.editor(target)
                    .newEntity()
                    .withOpenMode(OpenMode.DIALOG)
                    .build();
            editor.show();
        } else {
            super.actionPerform(component);
        }
    }
}
@ActionType(DialogEditAction.ID)
public class DialogEditAction extends EditAction {

    public static final String ID = "edit_dialog";

    public DialogEditAction() {
        super(ID);
    }

    public DialogEditAction(String id) {
        super(id);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void actionPerform(Component component) {
        // if standard behaviour
        if (!hasSubscriptions(ActionPerformedEvent.class)) {
            Entity editedEntity = target.getSingleSelected();
            Screen editor = screenBuilders.editor(target)
                    .editEntity(editedEntity)
                    .withOpenMode(OpenMode.DIALOG)
                    .build();
            editor.show();
        } else {
            super.actionPerform(component);
        }
    }
}
<actions>
    <action id="create" type="create_dialog"/>
    <action id="edit" type="edit_dialog"/>
...
</actions>

Similarly to screens, the actions base package must be registered in the web-springs.xml

<gui:actions base-packages="com.company.demo.gui.actions"/>

Regards,
Gleb

1 Like

In this case, do I force it in the browser or Editor xml file?

1 Like

In the screen you want to be opened as dialog.

Thank you so much Gleb

@gorelov but we still have xml attribute openType for element action. Consider this is a bug?

It is available only for legacy screens. Unfortunately, we cannot remove it since we use the same XSD for old/new screens.

Thanks Yuriy, but in this case it would be confused. Especially for those who move from v6 to v7.

BTW,can I know why remove it? There is chanllege in the China forum.:blush:

2 Likes