MyActionと呼ばれるmagnoliacmsでカスタムアクションを作成しました。アクションが実行されるページのノード名を取得したいのですが。代わりに、ページ名に空の文字列を取得しています。
これはコードです:
package ch.xxx.module.versioning;
import info.magnolia.ui.api.action.Action;
import info.magnolia.ui.api.action.ActionExecutionException;
import javax.jcr.LoginException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import info.magnolia.context.Context;
import info.magnolia.context.MgnlContext;
public class MyAction implements Action {
@Override
public void execute() throws ActionExecutionException {
String nodeName= "null";
Context context = MgnlContext.getInstance();
Session session = null;
try {
session = context.getJCRSession("website");
} catch (LoginException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RepositoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Get root node
try {
nodeName = session.getRootNode().getName();
} catch (RepositoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Executed MyAction for node: " + nodeName);
}
}
ありがとう@ Ducaz035!
カスタムアクションで機能したソリューションは次のとおりです。
public class MyAction extends AbstractMultiItemAction<zzzVersioning> {
public MyAction(zzzVersioning definition, JcrItemAdapter item, UiContext uiContext) {
super(definition, item, uiContext);
// TODO Auto-generated constructor stub
}
@Override
public void execute() {
try {
System.out.println("Ran execute Action! " + getItems().get(0).getJcrItem().getName());
} catch (RepositoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void executeOnItem(JcrItemAdapter item) throws Exception {
// TODO Auto-generated method stub
}
@Override
protected String getSuccessMessage() {
// TODO Auto-generated method stub
return null;
}
@Override
protected String getFailureMessage() {
// TODO Auto-generated method stub
return null;
}
}
カスタムアクション定義のコードは次のとおりです。
public class zzzVersioning extends CommandActionDefinition {
public zzzVersioning() {
this.setImplementationClass(MyAction.class);
}
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加