我尝试在木兰中的页面应用程序的操作栏中实现类似于Magnolia 6.0 custom action implementation的自定义操作。

我的实现是:

package ch.zzz.module.versioning;


import info.magnolia.ui.api.action.Action;
import info.magnolia.ui.api.action.ActionExecutionException;
import info.magnolia.ui.api.action.ConfiguredActionDefinition;

public class ZzzVersioning extends ConfiguredActionDefinition {

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

class MyAction implements Action {



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


页面应用程序的动作配置使用ch.zzz.module.versioning.ZzzVersioning类,我在页面应用程序的动作栏中的项目下列出了该动作。

配置应用
模块>页面>应用程序>页面>子应用程序>浏览器>操作> MyActions
-class = ch.zzz.module.versioning.ZzzVersioning

模块>页面>应用程序>页面>子应用程序>浏览器>操作栏>部分> pageActions> importExportActions> items-MyAction

单击操作栏中的MyAction时,出现错误消息:Could not instantiate action class for action: MyAction.

这是我在日志中得到的:

2019-11-22 08:37:26,498 ERROR fo.magnolia.ui.contentapp.browser.BrowserPresenter: An error occurred while executing action [MyAction]
info.magnolia.ui.api.action.ActionExecutionException: Could not instantiate action class for action: MyAction


...然后在堆栈末尾:

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


有什么建议如何使它工作?


感谢©Ducay035,我能够找到自定义版本控制类的解决方案:

package ch.zzz.module.versioning;

import info.magnolia.ui.api.action.CommandActionDefinition;

/**
 * Definition interface for the MyAction page action.
 */

public class UzhVersioning extends CommandActionDefinition {

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


和MyAction类:

public class MyAction extends AbstractMultiItemAction<Versioning>  {

    public MyAction(Versioning definition, JcrItemAdapter item, UiContext uiContext) {
        super(definition, item, uiContext);
        // TODO Auto-generated constructor stub
    }




    @Override
    public void execute() {
    ////your action code here
    }

最佳答案

您必须将您的课程公开,以便IOC系统可以找到它。但是,如果使用注入机制,则可以使构造函数成为私有函数。

干杯,

希望能有所帮助

10-08 19:33