Foros de discusión

Triggering events on portlet nav away

Voltaire Selverian, modificado hace 11 años.

Triggering events on portlet nav away

New Member Mensajes: 6 Fecha de incorporación: 7/11/12 Mensajes recientes
Hi,

I'm fairly new to Liferay and needs some help.

My company is porting over our current web application (a non-portal J2EE application running on WAS) to a portal based application on Liferay running on JBoss. One of the requirements we need to maintain is for specific logic to be invoked on page loading and unloading, or as it now is portlet loading and unloading if you will. This was easily accomplished in our past architecture by associating JavaScript functions to the onload and onunload events defined on the JSP pages's body tag. However, this doesn't work any longer in a portal environment as I'm sure you already know...

I've done quite a bit of searching on this topic already. It doesn't appear anyone has ever encountered this particular problem/task as nothing is posted. At first I thought that perhaps IPC might be the solution to my problem. By trying out some code, I found that defining a listener on the portletReady event was sufficient for capturing the loading of the portlet. However, there doesn't appear to be anyway to capture the unloading event; I had thought that closePortlet might work, but this appears to be the event for closing the portlet (e.g., the 'x' in the top right corner), which we've disabled.

The reason we need this is again to satisfy requirements. Any help would be greatly appreciated. Here are two things that I've tried:


Liferay.on(
    'portletReady',
    function(event) {
        if ('_' + event.portletId + '_' == '<portlet:namespace />') {
            onLoading();
        }
    }
);


And


Liferay.on(
    'closePortlet',
    function(event) {
        onUnloading();
    }
);
Voltaire Selverian, modificado hace 11 años.

RE: Triggering events on portlet nav away

New Member Mensajes: 6 Fecha de incorporación: 7/11/12 Mensajes recientes
Is there really no response on this that someone can offer?
Mitchell Roberts, modificado hace 6 años.

RE: Triggering events on portlet nav away

New Member Mensajes: 6 Fecha de incorporación: 10/03/17 Mensajes recientes
Hello Voltaire!

Just wondering if you ever found a solution to your problem? I am in a similar scenario and need to trigger some actions when a portlet is unloaded, and a new page is navigated to.
Voltaire Selverian, modificado hace 5 años.

RE: Triggering events on portlet nav away

New Member Mensajes: 6 Fecha de incorporación: 7/11/12 Mensajes recientes

Unfortunately, no.

thumbnail
Olaf Kock, modificado hace 5 años.

RE: Triggering events on portlet nav away

Liferay Legend Mensajes: 6403 Fecha de incorporación: 23/09/08 Mensajes recientes

The problem is that you're not "navigating away from a portlet", you're navigating away from a page. And maybe not even that: You might just briefly interact with another portlet on the same page, then continue with the first one. This can be complicated by working in multiple browser tabs, so you can't even react server-side when another URL or page is requested, as the original page is still open.

I'd say that this is fundamentally unsolveable - and a typical question where I'd counter-ask: What is the problem that you tried solving this way? I'd assume that there's a different solution that someone could come up with.

Voltaire Selverian, modificado hace 5 años.

RE: Triggering events on portlet nav away

New Member Mensajes: 6 Fecha de incorporación: 7/11/12 Mensajes recientes

Hi Olaf, Thanks for your response. In the end, we were able to get around this issue by page re-design and req. changes..

Note however, that most modern browsers (Chrome specifiically) apparently no longer support the onunload event and discourage custom pop-ups from displaying on navigation events. We've moved to using the onbeforeunload as a result, which still appears to fire and allow us to do what we intended. However, recently, with our migration to Liferay 7, we've noted issues even with this; in short, the onbeforeunload was not triggering anymore. The onbeforeunload event was firing in stand-alone code, but not in Liferay 7. While researching this issue, I came across a defect that was raised against Liferay 7 (https://issues.liferay.com/browse/LPS-76019) and apparently resolved with patch 35. But I have not been able to confirm this yet, as we're having some issues applying the patch and we've had to open a ticket with Liferay.