4

So I have googled whole day, got few answers how to do this, and they all fail. Not to mention all solutions were >3yr old. I'm using LR 6.1 CE. Would be grateful for simple working example, because other answers always got me to null value.

McAnder
  • 113
  • 1
  • 7

3 Answers3

4

There are 2-3 ways to do this, but try this one.

get the portletSession from the portletRequest. Use setAttribute() method with 3 parameters. The 3rd parameter should be PortletSession.APPLICATION_SCOPE.

Get the value from the 2nd portlet from the portlet session. Use the same APPLICATION_SCOPE to get it.

Edit:

Also you would require to make the value of the following tags as false in liferay-portlet.xml to share parameters

<private-request-attributes>false</private-request-attributes>
<private-session-attributes>false</private-session-attributes>

You can read more about these parameters in the DTD.

Prakash K
  • 11,669
  • 6
  • 51
  • 109
Felix Christy
  • 2,179
  • 1
  • 19
  • 32
  • the most common passing mechanisms are 1) Passing parameters to url and reading from the originalHttpServletRequest 2) Sharing via PortletSession 3) Via eventing, the one that I proposed is most common, hope that will help you – Felix Christy Jun 21 '12 at 07:41
  • I found other solution that works, and from my perspective it is more newbie friendly. Pass it! and receive with <% String param = request.getParameter("test"); %> – McAnder Jun 21 '12 at 10:28
  • Yup, this will defn work when you have data as string, if you have custom object, at that point, you have to use session or events! :) – Felix Christy Jun 21 '12 at 10:32
  • ... use session or events or public-render-parameters – Prakash K Jun 22 '12 at 05:18
1

This code call an Action from other portlet and send 2 params

you can use :

liferay-portlet:renderURL
liferay-portlet:actionURL

<liferay-portlet:actionURL name="addWallEntry" plid="<%= portletId2 %>" portletName="3_WAR_socialnetworkingportlet" var="shareUrl">
<portlet:param name="redirect" value="<%= viewFolderURL.toString() %>" />
<portlet:param name="comments" value="<%= shareMessage %>" />

 </liferay-portlet:actionURL>

<liferay-ui:icon image="share" url="<%= shareUrl %>"/>

and you have to know the concepts of plid: referenced page layout id portletName: referenced portlet name

The renderURL and the actionURL are tags provided by Liferay that extend the standard tlds. Note: this kind of communication is not part of the standard of the portlets JSR168 and JSR286.

The plid is the id of the page where we deploy one portlet, we can use LayOutLocalService to seek the id, or query it in the database directly.

The portletName is the identifier of the portlet and is part of the deployment descriptor of the portlet. This id is composed by portletId+WAR+thenameofwarthatencapsulatestheportlet and optionally the INSTANCE if the portlet is instanciable.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
schwertfisch
  • 4,549
  • 1
  • 19
  • 32
0

I attach a demo of a simple liferay-portlet.xml with the request and session attributes.

<?xml version="1.0"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.1.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_1_0.dtd">

<liferay-portlet-app>
    <portlet>
        <portlet-name>testRedirect</portlet-name>
        <icon>/icon.png</icon>
        <instanceable>false</instanceable>
        <private-request-attributes>false</private-request-attributes>
        <private-session-attributes>false</private-session-attributes>
        <header-portlet-css>/css/main.css</header-portlet-css>
        <footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
        <css-class-wrapper>testRedirect-portlet</css-class-wrapper>
    </portlet>
    <role-mapper>
        <role-name>administrator</role-name>
        <role-link>Administrator</role-link>
    </role-mapper>
    <role-mapper>
        <role-name>guest</role-name>
        <role-link>Guest</role-link>
    </role-mapper>
    <role-mapper>
        <role-name>power-user</role-name>
        <role-link>Power User</role-link>
    </role-mapper>
    <role-mapper>
        <role-name>user</role-name>
        <role-link>User</role-link>
    </role-mapper>
</liferay-portlet-app>
Dani
  • 3,744
  • 4
  • 27
  • 35
user1782634
  • 187
  • 1
  • 11