Fórum

How can i transfer a parameter from portlet A to portlet B

Amine RYANE, modificado 12 Anos atrás.

How can i transfer a parameter from portlet A to portlet B

Junior Member Postagens: 36 Data de Entrada: 12/03/12 Postagens Recentes
Hi,
I have 2 portlet : Portlet A and portlet B, my question is how can i transfer a parameter from portlet A to portlet B and how can i create a link betwen them.

Thanks a lot.
thumbnail
David H Nebinger, modificado 12 Anos atrás.

RE: How can i transfer a parameter from portlet A to portlet B

Liferay Legend Postagens: 14916 Data de Entrada: 02/09/06 Postagens Recentes
You cannot mix terms here, because there are many different answers based upon what you are trying to do.

For example, are you talking an internal value from portlet A that is visible in portlet B? Are you talking about an action and/or render parameter? Are you talking about a property value from a property file?

For the link, are you talking an IPC link or an actual HTML link?
Amine RYANE, modificado 12 Anos atrás.

RE: How can i transfer a parameter from portlet A to portlet B

Junior Member Postagens: 36 Data de Entrada: 12/03/12 Postagens Recentes
Thanks David for replay,
To be honest with you i'm new user of Liferay, so i can't make a clear difference betwen what you seggested to me but i can explain better my problem emoticon

In portlet A i can get informations and i want to transfer those informations to portlet B, this is my view.jsp [portlet A] (there is one page in portlet A):

<%
/**
* Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

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

<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>


<%@page import="com.liferay.portal.kernel.util.WebKeys"%>
<%@page import="com.liferay.portal.model.User"%>
<%@page import="com.liferay.portal.theme.ThemeDisplay"%>

<%@page import="javax.portlet.RenderRequest"%>
<%@page import="javax.portlet.PortletRequest"%>

<%@page import="com.liferay.portal.util.PortalUtil"%>

<%@page import="javax.servlet.http.HttpServletRequestWrapper"%>
<%@page import="javax.servlet.http.HttpServletRequest"%>
<%@page import="java.util.Map"%>


<%@ page import="com.liferay.portal.CookieNotSupportedException" %>
<%@ page import="com.liferay.portal.NoSuchUserException" %>
<%@ page import="com.liferay.portal.PasswordExpiredException" %>
<%@ page import="com.liferay.portal.UserEmailAddressException" %>
<%@ page import="com.liferay.portal.UserLockoutException" %>
<%@ page import="com.liferay.portal.UserPasswordException" %>
<%@ page import="com.liferay.portal.UserScreenNameException" %>
<%@ page import="com.liferay.portal.kernel.language.LanguageUtil" %>
<%@ page import="com.liferay.portal.kernel.util.Constants" %>
<%@ page import="com.liferay.portal.kernel.util.GetterUtil" %>
<%@ page import="com.liferay.portal.kernel.util.HtmlUtil" %>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%@ page import="com.liferay.portal.kernel.util.PortalClassInvoker" %>
<%@ page import="com.liferay.portal.kernel.util.PropsUtil" %>
<%@ page import="com.liferay.portal.security.auth.AuthException" %>
<%@ page import="com.liferay.portal.service.UserLocalServiceUtil" %>
<%@ page import="javax.portlet.WindowState" %>


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

<portlet:defineObjects />

This is the <b>My Greeting</b> portlet.
<div>
Hello <%= renderRequest.getRemoteUser()%>

</div>
<%
User user = PortalUtil.getUser(request);
System.out.println(user.getFirstName());
String amine = (String) user.getFirstName();

%>
<div>
Hi <%= amine%>
</div>
<liferay-portlet:renderURL var="linkURL" portletName="MyProject_WAR_MyProject" windowState="maximized" />
<a href="<%= linkURL%>">link to portlet-B</a>


******* I want to transfer the parameter 'amine' to portlet B*******
Thanks.
thumbnail
David H Nebinger, modificado 12 Anos atrás.

RE: How can i transfer a parameter from portlet A to portlet B

Liferay Legend Postagens: 14916 Data de Entrada: 02/09/06 Postagens Recentes
There is no reason to pass that value around. Since it comes directly from the user record, portlet B should pull it from there.

User's first name is not something that is going to change on A and therefore does not need to be passed to B, as B can get it on it's own.

A and B should always be independent of each other unless you have a specific reason to tie them together (i.e. A contains a record list and B shows the detail of the selected record in A).

You don't want to artificially manufacture links between them because that will tie your portlets together. In your example, you could never have portlet B on a page without portlet A also being on the page when in reality B could operate all on it's own by also pulling the user from the theme (or request or whatever).
thumbnail
André Bunse, modificado 12 Anos atrás.

RE: How can i transfer a parameter from portlet A to portlet B (Resposta)

Junior Member Postagens: 85 Data de Entrada: 16/03/12 Postagens Recentes
Hi Amine,

you are always one step before me ;)

one of my next todos is "what's the best way to interchange information between 2 portlets?"

so i think informing Portlet B with string "amine" is only a test case

my todo list has one link right now for later studies (hoping it was the right way then)

Portlet to portlet communication


HTH
André
thumbnail
David H Nebinger, modificado 12 Anos atrás.

RE: How can i transfer a parameter from portlet A to portlet B

Liferay Legend Postagens: 14916 Data de Entrada: 02/09/06 Postagens Recentes
Andre, that is the right way to do portlet IPC.

Amine's question was not really how to do IPC per se, the example was just using the first name value. So I didn't know that they were specifically asking about IPC because the question really had nothing to do with it...

But again, you really need to know that you have to have two (or more) portlets tied together. If they do not need to be coupled, don't go out of your way coupling them...
thumbnail
André Bunse, modificado 12 Anos atrás.

RE: How can i transfer a parameter from portlet A to portlet B

Junior Member Postagens: 85 Data de Entrada: 16/03/12 Postagens Recentes
David H Nebinger:
Amine's question was not really how to do IPC per se, the example was just using the first name value. So I didn't know that they were specifically asking about IPC because the question really had nothing to do with it...

your are right, i'm worked often with trainees, so i can imagine what they means even if they ask anything else emoticon


Keep on coding
André
Amine RYANE, modificado 12 Anos atrás.

RE: How can i transfer a parameter from portlet A to portlet B

Junior Member Postagens: 36 Data de Entrada: 12/03/12 Postagens Recentes
Thanks for your replay.
I solved the problem by following steps in André's link.
Thanks a lot.