Magnolia 6.0 custom action implementation

大城市里の小女人 提交于 2020-01-15 05:20:10

问题


I try to implement custom action in actionbar. My implementation is

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 is registered via yaml file and is shown in the UI. When I click action button I get this error:

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:?]

What kind of constructor should I provide to make it work?


回答1:


I figured it out. My implementation's constructor was missing @Inject annotation. Working version below:

class MyAction implements Action {

    @Inject
    protected MyAction() {
        //noop
    }


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


来源:https://stackoverflow.com/questions/54704380/magnolia-6-0-custom-action-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!