Programmatic Actions

Any appropriate component can have actions created and set programmatically in the view controller. The method is simple but can make the controller verbose and does not allow reusing the action in XML.

Below example makes the button show “Hello” when clicked:

  1. Inject the component to the view controller:

    @ViewComponent
    private JmixButton actionButton;
  2. Set the action by instantiating the BaseAction class.

    @Subscribe
    public void onInit(final InitEvent event) {
        actionButton.setAction(
                new BaseAction("action")
                        .withText("Click me!")
                        .withHandler(actionPerformedEvent -> notifications.show("Action performed!")));
    }
See how this compares to the equivalent example in Custom action type, which allows the action to be reused.