2

In portlet What is the best way to read namespace parameter in action method. My form contains

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

option1:

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

option2:

request.getParameter("param1");

option1 does not work in liferay, but does seem will work in websphere. option2 works fine in liferay 6.2. option1 seems to work in before 6.1.

Can anyone please tell me what is the jsr 286 compliant way?

Dave
  • 21,524
  • 28
  • 141
  • 221
Kalaiselvam M
  • 1,050
  • 1
  • 16
  • 25

3 Answers3

4

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."

Montecarlo
  • 1,239
  • 1
  • 11
  • 24
  • 1
    Thanks Carlos,This work around will work only if we have parameters in jsp without namespace prefixed. The issue at hand is, we have to have namespace associated with parameters in jsp and need to get those parameters in portlet and that portlet has to be deployed in liferay,weblogic and webphere. Note webphere and weblogic works fine, need to find a fix or work around in liferay 6.2 – Kalaiselvam M Feb 18 '14 at 12:38
  • As @Kalai already commented to the OP, please refer to https://issues.liferay.com/browse/LPS-44604 . (This is already cross-linked from there. Will try to help drive-forward a resolution on the underlying issue from there.) – ziesemer Jul 08 '15 at 14:03
0

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.

Georgy Gobozov
  • 13,633
  • 8
  • 72
  • 78
  • Hi Georgy Gobozov, Thanks for your answer. – Kalaiselvam M Feb 06 '14 at 04:15
  • Hi Georgy Gobozov, Thanks for your answer. let us say i am creating a portlet which uses namespaces for parameter passing and i want to deploy that portlet in different environment like liferay,websphere and weblogic etc. So i am looking to write code which would work in all platform. so are you saying that is not possible? – Kalaiselvam M Feb 06 '14 at 04:22
  • it should work on all platforms. part of portlet specification and if portal implement jsr 168 or jsr 286 this tag should work – Georgy Gobozov Feb 06 '14 at 14:53
  • I tested it,request.getParameter("param1"); does not work in websphere and request.getParameter(response.getNamespace() + "param1"); does not work in liferay. So unable to write generic method. – Kalaiselvam M Feb 12 '14 at 14:19
  • Impossible. You doing something wrong. Show your code pls – Georgy Gobozov Feb 12 '14 at 14:53
  • added the code as answer since i am not able to add it here – Kalaiselvam M Feb 12 '14 at 15:33
0

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

Kalaiselvam M
  • 1,050
  • 1
  • 16
  • 25
  • And? You send only one form parameter with name = renderPage and I guess you get it in processAction "sites/Component Guide/Home.page". Of course request.getParameter(Constants.RENDER_PAGE)) will be null because you don't send it from form to portlet – Georgy Gobozov Feb 12 '14 at 18:54
  • But the problem is, in liferay it is reverse and the reason being said in liferay is that namespace will be applied by default so you do not have to prefix the namespace in our action method. With the same code the log statement would print DEBUG ..... renderPage==Namespace=>null DEBUG ..... renderPage==withoutnamespace=>sites/Component Guide/Home.page – Kalaiselvam M Feb 13 '14 at 05:25
  • 1
    @Kalai I run into your exact problem two days ago (I have not solved it yet). I think that Liferay is working wrong. 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." Someone open an issue in Liferay's JIRA: https://issues.liferay.com/browse/LPS-39775 – Montecarlo Feb 13 '14 at 19:28