首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Magnolia 6.0自定义操作实现

Magnolia 6.0自定义操作实现
EN

Stack Overflow用户
提问于 2019-02-15 15:20:11
回答 1查看 483关注 0票数 2

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

代码语言:javascript
复制
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!");
    }
}

Action通过yaml文件注册,并显示在UI中。当我单击操作按钮时,我得到这个错误:

代码语言:javascript
复制
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$4(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:?]

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-15 20:28:53

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

代码语言:javascript
复制
class MyAction implements Action {

    @Inject
    protected MyAction() {
        //noop
    }


    @Override
    public void execute() throws ActionExecutionException {
        System.out.println("Yo!");
    }
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54704380

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档