问题
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