3.5.5.2. Standard Actions

Standard actions are provided by the framework to solve common tasks, such as invocation of an edit screen for an entity selected in a table. A standard action should be declared in the screen XML descriptor by specifying its type in the type attribute.

There are two categories of standard actions:

  • List actions work with collections of entities that are displayed in tables or trees. These are CreateAction, EditAction, ViewAction, RemoveAction, AddAction, ExcludeAction, RefreshAction, ExcelAction, BulkEditAction.

    When a list action is added to a table, tree or data grid, it can be invoked from the component’s context menu item and by its predefined keyboard shortcut. Usually, the action is also invoked by a button added to the buttons panel.

    <groupTable id="customersTable">
        <actions>
            <action id="create" type="create"/>
            ...
            <buttonsPanel>
                <button id="createBtn" action="customersTable.create"/>
                ...
  • Picker field actions work with the content of the field. These are LookupAction, OpenAction, OpenCompositionAction, ClearAction.

    When a picker action is added to the picker field component, it is automatically represented by a button inside the field.

    <pickerField id="customerField">
        <actions>
            <action id="lookup" type="picker_lookup"/>
            ...

Each standard action is implemented by a class annotated with @ActionType("<some_type>"). The class defines the action’s default properties and behavior.

You can specify any basic action XML attributes to override common action properties: caption, icon, shortcut, etc. For example:

<action id="create" type="create" caption="Create customer" icon="USER_PLUS"/>

Since CUBA 7.2, standard actions have additional properties that can be set in XML or using setters in Java. In XML, additional properties are configured using the nested <properties> element, where each <property> element corresponds to a setter existing in this action class:

<action id="create" type="create">
    <properties>
        <property name="openMode" value="DIALOG"/>
        <property name="screenClass" value="com.company.demo.web.CustomerEdit"/>
    </properties>
</action>

The same can be done in Java controller:

@Named("customersTable.create")
private CreateAction createAction;

@Subscribe
public void onInit(InitEvent event) {
    createAction.setOpenMode(OpenMode.DIALOG);
    createAction.setScreenClass(CustomerEdit.class);
}

If a setter accepts a functional interface, you can install a handler method in the screen controller. For example, CreateAction has setAfterCommitHandler(Consumer) method which is used to set a handler to be invoked after the created entity is committed. Then you can provide the handler as follows:

@Install(to = "customersTable.create", subject = "afterCommitHandler")
protected void customersTableCreateAfterCommitHandler(Customer entity) {
    System.out.println("Created " + entity);
}

There is a common enabledRule handler available to all actions, which allows you to set the action "enabled" state depending on the situation. In the example below, it disables RemoveAction for some entities:

@Inject
private GroupTable<Customer> customersTable;

@Install(to = "customersTable.remove", subject = "enabledRule")
private boolean customersTableRemoveEnabledRule() {
    Set<Customer> customers = customersTable.getSelected();
    return canBeRemoved(customers);
}

See the next sections for detailed description of the actions provided by the framework and the Custom Action Types section for how to create your own action types or override the existing ones.