【问题标题】:How to customize com.liferay.portlet.wiki.action.GetPageAttachmentAction using Ext Plugin如何使用 Ext 插件自定义 com.liferay.portlet.wiki.action.GetPageAttachmentAction
【发布时间】:2015-08-01 07:08:07
【问题描述】:

我正在使用 Liferay 6.2,我想修改 GetPageAttachmentAction

我想在strutsExecute 中添加以下代码以在文件名中包含标题:

public ActionForward strutsExecute(
        ActionMapping actionMapping, ActionForm actionForm,
        HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    long nodeId = ParamUtil.getLong(request, "nodeId");
    String title = ParamUtil.getString(request, "title");
    String fileName = ParamUtil.getString(request, "fileName");
    // Here my change:
    int pos = fileName.indexOf(CharPool.SLASH); 
    if (pos >= 0) { 
        title = fileName.substring(0, pos); 
        fileName = fileName.substring(pos + 1);
    }
    ...

如果我通过使用自定义类扩展 BaseStrutsPortletAction 来为此更改创建挂钩插件,则它不会提供 strutsExecute() 来覆盖。

我应该改用 Ext 插件吗?如果是,那么建议我配置Ext插件来修改GetPageAttachmentAction。

【问题讨论】:

  • 您能在strutsExecute 中显示您想要更改的内容吗?
  • 我想在 strutExecute() 方法调用的 getFile() 方法中添加代码来分隔文件 wiki 标题和文件名。所以我想添加以下代码 int pos = fileName.indexOf(CharPool.SLASH); if (pos != -1) { title = fileName.substring(0, pos);文件名 = 文件名.substring(pos + 1); }
  • 我将这些信息整合到您的问题中

标签: liferay liferay-6


【解决方案1】:

您可以执行以下任一操作:Hook 插件或 Ext 插件。

但在这里钩子似乎更有意义:

public class MyGetPageAttachmentAction extends BaseStrutsPortletAction {

  public void processAction(
      StrutsPortletAction originalStrutsPortletAction,
      PortletConfig portletConfig, ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    String title = ParamUtil.getString(actionRequest, "title");
    String fileName = ParamUtil.getString(actionRequest, "fileName");

    // Your code:
    int pos = fileName.indexOf(CharPool.SLASH); 
    if (pos >= 0) { 
      title = fileName.substring(0, pos); 
      fileName = fileName.substring(pos + 1);
    }

    // Wrap request to add your new parameters (the original request parameters are immutable)
    DynamicActionRequest dynamicActionRequest = new DynamicActionRequest(actionRequest, true);
    dynamicActionRequest.setParameter("fileName", fileName);
    dynamicActionRequest.setParameter("title", title);

    // And delegate to original action
    originalStrutsPortletAction.processAction(portletConfig, dynamicActionRequest, actionResponse);
  }
}

(根据您的问题,我猜您在 liferay-hook.xml 中已经有了正确的设置)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-05
    • 1970-01-01
    相关资源
    最近更新 更多