2

在 portlet 中,在 action 方法中读取命名空间参数的最佳方法是什么。我的表格包含

<input id="<portlet:namespace/>param1"  name="<portlet:namespace/>param1" value='hello'/>

选项1:

request.getParameter(response.getNamespace() + "param1");

选项2:

request.getParameter("param1");

option1 在 liferay 中不起作用,但似乎在 websphere 中起作用。option2 在 liferay 6.2 中运行良好。option1 似乎在 6.1 之前有效。

谁能告诉我什么是符合 jsr 286 的方式?

4

3 回答 3

4

正如我在对这个问题的回答的评论中提到的,问题出在 Liferay 6.2 上,因为 IBM WebSphere 和 Liferay 的早期版本正在按预期工作。

为了解决这个问题,我将元素添加<requires-namespaced-parameters>false</requires-namespaced-parameters>到了portletliferay-portlet.xml的目录中。/WEB-INF通过这样做,HTML 表单的参数不是“命名空间”。

示例/WEB-INF/liferay-portlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<liferay-portlet-app>
  <portlet>
    <portlet-name>Portlet name</portlet-name>
    <requires-namespaced-parameters>false</requires-namespaced-parameters>
    <instanceable>true</instanceable>
    <ajaxable>false</ajaxable>
  </portlet>
</liferay-portlet-app>

如果将此元素添加到 中liferay-portlet.xml,portlet 在以前的 Liferay 版本中仍然可以正常工作(我使用版本 5.5 和 6.1 进行了测试)。它也适用于其他 portlet 包含,因为它们忽略此文件。

我声称 Liferay 的行为不正确,因为 JSR-286 规范说明了以下内容(在规范的第 76 页顶部):

如果 portlet 命名空间或编码 URL 参数或表单参数,它们还负责删除命名空间。portlet 容器不会删除 portlet 对这些参数所做的任何命名空间。”

于 2014-02-14T11:03:42.743 回答
0

最后的日志语句来自在webphere中运行代码

 <%@ taglib uri='http://java.sun.com/portlet' prefix='portlet'%>

    <form name="<portlet:namespace />"
                action="<portlet:actionURL windowState='normal'> <portlet:param name='action' value='processAction' /></portlet:actionURL>"
                method="post"><br />
    <input id="<portlet:namespace/>renderPage"
                name="<portlet:namespace/>renderPage"
                value='<%=request.getAttribute(Constants.RENDER_PAGE)%>'><br />
    </form>

     @Override
      public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException
      {
        if (mLogger.isDebugEnabled())
        {
          mLogger.debug("processAction:: Request Parameter Map:" + request.getParameterMap());
        }
        // Make all ActionRequest Parameter for RenderRequest
        response.setRenderParameters(request.getParameterMap());
        if (mLogger.isDebugEnabled())
        {
          mLogger.debug("processAction:: Latest changes are there");
          mLogger.debug(Constants.RENDER_PAGE + "==Namespace=>"+request.getParameter(response.getNamespace()+Constants.RENDER_PAGE));
          mLogger.debug(Constants.RENDER_PAGE + "==withoutnamespace=>"+request.getParameter(Constants.RENDER_PAGE));
        }

2014-02-12 19:35:23,877 DEBUG ..... renderPage==Namespace=>sites/Component Guide/Home.page 2014-02-12 19:35:23,877 DEBUG ..... renderPage==withoutnamespace =>空

于 2014-02-12T15:29:32.637 回答
0

没有“符合 jsr 286 的方式”您可以同时使用这两种方法。当您在同一个门户页面上有多个 portlet 实例时,使用标记的主要目的是将确切的参数传递给确切的 portlet。在这种情况下,不同 portlet 的相同 html 输入具有不同的名称,并且每个 portlet 将获得自己的页面值。

于 2014-02-05T15:13:08.057 回答