MVCActionCommandのオーバーライド

Liferay MVC actionコマンドに追加したい場合は、追加できます。OSGiフレームワークを使用すると、MVCコマンドにロジックを追加する手順に従って、MVC actionコマンドをオーバーライドできます。 カスタムMVC actionコマンドを、オリジナルと同じプロパティを持つが、サービスランキングが高いOSGiコンポーネントとして登録します。

通常、カスタムMVC actionコマンドはBaseMVCActionCommand クラスを拡張し、voidを返すdoProcessActionメソッドをオーバーライドします。元のサービスへの参照を取得,し、独自のロジックの後に呼び出すことで、アクションメソッドの元の動作にロジックを追加します。 たとえば、次のMVCActionCommandオーバーライドは、元の処理を続行する前に、ブログエントリでdeleteアクションが呼び出されるかどうかを確認し、ログにメッセージを出力します。

@Component(
property = {
"javax.portlet.name=" + BlogsPortletKeys.BLOGS_ADMIN,
"mvc.command.name=/blogs/edit_entry",
"service.ranking:Integer=100"
},
service = MVCActionCommand.class
)
public class CustomBlogsMVCActionCommand extends BaseMVCActionCommand {

@Override
protected void doProcessAction
(ActionRequest actionRequest, ActionResponse actionResponse)
throws Exception {

String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

if (cmd.equals(Constants.DELETE)) {
System.out.println("Deleting a Blog Entry");
}

mvcActionCommand.processAction(actionRequest, actionResponse);
}

@Reference(
target = "(component.name=com.liferay.blogs.web.internal.portlet.action.EditEntryMVCActionCommand)")
protected MVCActionCommand mvcActionCommand;

}

既存のロジックの前にMVC actionコマンドロジックを追加するのは簡単で、新しいコードと古いコードの間の疎結合を維持します。

関連トピック

MVC Action Command

Adding Logic to MVC Commands

Overriding MVCRenderCommands

Converting StrutsActionWrappers to MVCCommands

« MVCRenderCommandのオーバーライドMVCResourceCommandのオーバーライド »
この記事は役に立ちましたか?
1人中1人がこの記事が役に立ったと言っています