0

I have been looking for a solution using which I can extend the liferay session when I do AJAX calls on my page. I found out that we can use Liferay.session.extend() to extend the liferay session. This I found out at extend session of Liferay when performing AJAX call

But am not able to call the extend method, in console I get the error Liferay.session is not defined.

What would be the problem?

Community
  • 1
  • 1
Seeker
  • 2,405
  • 5
  • 46
  • 80

1 Answers1

1

If you are making the call in a JSP than you can make the call inside the tag <aui:script> like this:

<aui:script use="liferay-session">
    Liferay.session.extend();
</aui:script>

Or

<aui:script use="liferay-session">
    function myCustomSessionExtend() {
        Liferay.session.extend();
    }
</aui:script>

Or if you are using a separate javascript file (*.js) then I think the following should work:

AUI().use('liferay-session', function(A) {
    Liferay.session.extend();
});

Or

function myCustomSessionExtend() {

    AUI().use('liferay-session', function(A) {
        Liferay.session.extend();
    });

}

From Liferay 6.0 onwards Liferay uses Alloy UI as there default javascript library. Alloy UI has a concept of sandboxing (the AUI().use (function(A) { ... }); creates a sandbox i.e. an isolated area for object) and modularity (it loads modules only when required, so liferay-session is one such module created using Alloy UI).

For more information you can view this blog and this document.

Hope this would help resolve your issue.

Prakash K
  • 11,669
  • 6
  • 51
  • 109
  • I tried your solution for the separate javascript file (*.js), but unfortunately it didn't work. What might be the reason? I am getting the same error- Liferay.Session not declared – Seeker Jan 02 '13 at 05:40