JSR 286 compliant namespace parameter

元气小坏坏 提交于 2019-12-06 12:33:49

As I mentioned in a comment of an answer to this question, the problem is with Liferay 6.2 because IBM WebSphere and previous versions of Liferay are working as expected.

To solve this problem, I added the element <requires-namespaced-parameters>false</requires-namespaced-parameters> to the liferay-portlet.xml of the /WEB-INF directory of the portlet. By doing this, the parameters of the HTML forms are not "namespaced".

Example of /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>

If you add this element to the liferay-portlet.xml, the portlet still works correctly in previous versions of Liferay (I tested with versions 5.5 and 6.1). It also works with other portlet contains because they ignore this file.

I claim that Liferay is behaving incorrectly because the JSR-286 spec says the following (top the page 76 of the spec):

If portlets namespace or encode URL parameters or form parameters they are also responsible for removing the namespace. The portlet container will not remove any namespacing the portlet has done on these parameters."

There is no "jsr 286 compliant way" You can use both approach. The main purpose of usage tag is pass exact parameter to exact porlet when you have multiple portlet instances on same portal page. In this case same html inputs of different portlets have different names and every portlet will get his own page value.

Log statements at the end are from running the code in 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=>null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!