Foren

Same javascript variables in 2 portlets?

thumbnail
lutz Bremen, geändert vor 12 Jahren.

Same javascript variables in 2 portlets?

Expert Beiträge: 291 Beitrittsdatum: 20.10.11 Neueste Beiträge
Hey guys,
it's the noob again^^....

i got a problem with my javascript. i got 2 portlets. the first one ist a portlet that just shows something and the second one is the "options" portlet. so i want when i click "on" on the right portlet that the left portlet starts working. an when i press "of" at the left one that the right one stops.

so how can i transfer the value of the variable from one portlet to another?

i hope u got a solution.

thanks in advance

Lutz
thumbnail
Ravi Kumar Gupta, geändert vor 12 Jahren.

RE: Same javascript variables in 2 portlets?

Liferay Legend Beiträge: 1302 Beitrittsdatum: 24.06.09 Neueste Beiträge
I guess what you want is like this..
You click on some button/link on Portlet A then you want to perform some actions in Portlet B. And the same behavior when you click something on Portlet B..
If this is the case then go for IPC. Check this link for IPC using events and render parameters http://java.sun.com/developer/technicalArticles/J2EE/sdk_portletcontaineru5/
thumbnail
srikanth velugoti, geändert vor 12 Jahren.

RE: Same javascript variables in 2 portlets?

Junior Member Beiträge: 79 Beitrittsdatum: 24.04.09 Neueste Beiträge
Using Inter portlet communication we can achieve the requirement.


1. Portlet session: this is one way of IPC

Step 1: set below attributes in Portlet1

liferay-portlet.xml :
<portlet>
<private-session-attributes>false</private-session-attributes>
</portlet>

Step 2: To set the Session:

PortletSession session = renderRequest.getPortletSession();
session.setAttribute("sessionValue",some-value , PortletSession.APPLICATION_SCOPE);
Step 3 : Get the Session Value in Portlet2

PortletSession ps = renderRequest.getPortletSession();
String tabNames = (String)ps.getAttribute("sessionValue ",ps.APPLICATION_SCOPE);

Thanks ,
Srikanth
thumbnail
Sagar A Vyas, geändert vor 12 Jahren.

RE: Same javascript variables in 2 portlets?

Liferay Master Beiträge: 679 Beitrittsdatum: 17.04.09 Neueste Beiträge
Hi Bremen,

Agree with Ravi.

You need IPC ,You can do it by way mentioned by Bremen too.

But i recommend use IPC inteand of session.

I have two good URL you can find enough information over there

http://liferaycms.blogspot.com/2011/07/inter-portlet-communication.html
http://www.mpowerglobal.com/web/zubair/home/-/blogs/172768

Hope this help emoticon

Thanks,
Sagar Vyas
thumbnail
lutz Bremen, geändert vor 12 Jahren.

RE: Same javascript variables in 2 portlets?

Expert Beiträge: 291 Beitrittsdatum: 20.10.11 Neueste Beiträge
sounds interesting but im entering the code in a web content display portlet directly.
thumbnail
Ravi Kumar Gupta, geändert vor 12 Jahren.

RE: Same javascript variables in 2 portlets?

Liferay Legend Beiträge: 1302 Beitrittsdatum: 24.06.09 Neueste Beiträge
Then Javascript should work fine. Just check the logic you applied. If possible share the code with us..
thumbnail
lutz Bremen, geändert vor 12 Jahren.

RE: Same javascript variables in 2 portlets?

Expert Beiträge: 291 Beitrittsdatum: 20.10.11 Neueste Beiträge
ok here the first thing that doenst work fine:

function toggleMe01(a){

  AlleAus01()

  var e=document.getElementById(a);
  if(!e)return true;
  if(e.style.display=="none"){
    e.style.display="block"
  } else {
    e.style.display="none"
  }
  return true;
}


// hier müssen alle Container-IDs eingetragen werden
function AlleAus01() {
  xxx1.style.display="none"
  xxx2.style.display="none"
   xxx3.style.display="none"
}


the second thing that doesnt work are the variables in the 2 portlets but i cant share the code
thumbnail
Raja Nagendra Kumar, geändert vor 12 Jahren.

RE: Same javascript variables in 2 portlets?

Expert Beiträge: 484 Beitrittsdatum: 02.03.06 Neueste Beiträge
You must use javascript with name spaces

check this.. http://developers.sun.com/portalserver/reference/techart/ajax-portlets.html

Regards,
Raja Nagendra Kumar,
C.T.O
www.tejasoft.com
thumbnail
lutz Bremen, geändert vor 12 Jahren.

RE: Same javascript variables in 2 portlets?

Expert Beiträge: 291 Beitrittsdatum: 20.10.11 Neueste Beiträge
that doenst solve any problem
thumbnail
Leo Pratlong, geändert vor 12 Jahren.

RE: Same javascript variables in 2 portlets?

Expert Beiträge: 363 Beitrittsdatum: 06.07.10 Neueste Beiträge
The process you want to stop is a JavaScript process?
In this case, maybe you could call your JS object in your second portlet then call a "stop" function on it. That's ugly, but if you are working only with JS, this should work.
If I understand well, you are developing jS in two Web Content Display? Is that right?
thumbnail
lutz Bremen, geändert vor 12 Jahren.

RE: Same javascript variables in 2 portlets?

Expert Beiträge: 291 Beitrittsdatum: 20.10.11 Neueste Beiträge
yes im developing something that in le left portlet is shown up. and in the right portlet i got the settings.

like this:

in the right portlet in the top bar there are 3 buttons. when i clock on button 1 i got a menu. when i click on button 2 i got another menu and on 3 anotherone. its only shown one menu everytime. i built that and in my local browser it works fine. but not in liferay........

second one is:
i want to press"all out" in the right portlet and then in the left portlet should nothing be schown.


u understand that?
thumbnail
Ravi Kumar Gupta, geändert vor 12 Jahren.

RE: Same javascript variables in 2 portlets?

Liferay Legend Beiträge: 1302 Beitrittsdatum: 24.06.09 Neueste Beiträge
Can you check in firebug and firefox error console if any error comes when you try to perform an action.. ??
thumbnail
lutz Bremen, geändert vor 12 Jahren.

RE: Same javascript variables in 2 portlets?

Expert Beiträge: 291 Beitrittsdatum: 20.10.11 Neueste Beiträge
in firebug there is no error that could be the reason. like i said. on my pc when i open the docu,emt it works but not in liferay. i cant unterstand that because the function works und is pretty short and simple