Magnolia 6.0 自定义操作实现

Magnolia 6.0 custom action implementation

我尝试在 actionbar 中实现自定义操作。我的实现是

package com.example;

import info.magnolia.ui.api.action.Action;
import info.magnolia.ui.api.action.ActionExecutionException;
import info.magnolia.ui.contentapp.detail.action.AbstractItemActionDefinition;

public class MyActionDefinition extends AbstractItemActionDefinition {

    public MyActionDefinition() {
        this.setImplementationClass(MyAction.class);
    }
}

class MyAction implements Action {

    @Override
    public void execute() throws ActionExecutionException {
        System.out.println("Yo!");
    }
}

A​​ction 通过 yaml 文件注册并显示在 UI 中。当我单击操作按钮时出现此错误:

Caused by: info.magnolia.objectfactory.MgnlInstantiationException: No suitable constructor found for class [class com.example.MyAction]
    at info.magnolia.objectfactory.ObjectManufacturer.newInstance(ObjectManufacturer.java:124) ~[magnolia-core-6.0.jar:?]
    at info.magnolia.objectfactory.guice.GuiceComponentProvider.newInstanceWithParameterResolvers(GuiceComponentProvider.java:132) ~[magnolia-core-6.0.jar:?]
    at info.magnolia.ui.framework.ioc.UiContextBoundComponentProvider.lambda$newInstanceWithParameterResolvers(UiContextBoundComponentProvider.java:113) ~[magnolia-ui-framework-6.0.jar:?]
    at info.magnolia.ui.framework.ioc.UiContextBoundComponentProvider.provideInCurrentScope(UiContextBoundComponentProvider.java:125) ~[magnolia-ui-framework-6.0.jar:?]
    at info.magnolia.ui.framework.ioc.UiContextBoundComponentProvider.newInstanceWithParameterResolvers(UiContextBoundComponentProvider.java:113) ~[magnolia-ui-framework-6.0.jar:?]
    at info.magnolia.ui.framework.ioc.UiContextBoundComponentProvider.newInstance(UiContextBoundComponentProvider.java:108) ~[magnolia-ui-framework-6.0.jar:?]
    at info.magnolia.ui.api.action.AbstractActionExecutor.createAction(AbstractActionExecutor.java:90) ~[magnolia-ui-api-6.0.jar:?]

我应该提供什么样的构造函数才能让它工作?

我明白了。我的实现的构造函数缺少 @Inject 注释。工作版本如下:

class MyAction implements Action {

    @Inject
    protected MyAction() {
        //noop
    }


    @Override
    public void execute() throws ActionExecutionException {
        System.out.println("Yo!");
    }
}