Custom Action Types
You can create your own action types or override existing standard types in your project.
For example, imagine that you need an action that would show the instance name of the currently selected entity in a dataGrid
. You would like to reuse this action in multiple views by specifying its type only. Below are the steps to create the action.
-
Create an action class and add the
@ActionType
annotation with the desired type name:package com.company.onboarding.view.actions; import com.vaadin.flow.component.Component; import io.jmix.core.MetadataTools; import io.jmix.flowui.Notifications; import io.jmix.flowui.action.ActionType; import io.jmix.flowui.action.list.ItemTrackingAction; import org.springframework.beans.factory.annotation.Autowired; @ActionType("showSelected") public class ShowSelectedAction<E> extends ItemTrackingAction<E> { @Autowired private MetadataTools metadataTools; @Autowired private Notifications notifications; public ShowSelectedAction(String id) { super(id); setText("Show Selected"); } @Override public void actionPerform(Component component) { if (getTarget() != null) { E selected = getTarget().getSingleSelectedItem(); if (selected != null) { notifications.create(metadataTools.getInstanceName(selected)).show(); } } } }
-
Now you can use the action in screen descriptors by specifying its type:
<action id="showSelected" type="showSelected"/>
If you want to override an existing type, register your new action class with the same type name in |
Was this page helpful?
Thank you for your feedback