gpt4 book ai didi

java - 自定义操作实现 Magnolia CMS

转载 作者:行者123 更新时间:2023-12-02 01:13:44 26 4
gpt4 key购买 nike

我尝试在 Magnolia 中的页面应用程序的操作栏中实现自定义操作,类似于 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 时,收到一条错误消息:无法实例化操作的操作类: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
}

最佳答案

您必须公开您的类(class),以便 IOC 系统可以找到它。但是,如果您使用注入(inject)机制,则可以使构造函数成为非私有(private)的。

干杯,

希望有帮助

关于java - 自定义操作实现 Magnolia CMS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58978240/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com