0
votes

I am using Liferay 6.2 as my portal platform. my question is if there is a way to load portlet via ajax? providing only the portlet id.

e.g.

this is the portlet info:

<portlet>
    <portlet-name>my_portlet</portlet-name>
    <instanceable>false</instanceable>
    <private-session-attributes>false</private-session-attributes>
    <header-portlet-javascript>/js/my_portlet/app.js</header-portlet-
</portlet>

<portlet>
    <portlet-name>my_portlet</portlet-name>
    <display-name>My Portlet</display-name>
    <portlet-class>com.ui.portlets.generic.GenericPortlet</portlet-class>
    <init-param>
        <name>view-template</name>
        <value>/view.jsp</value>
    </init-param>
    <expiration-cache>0</expiration-cache>
    <supports>
        <mime-type>text/html</mime-type>
    </supports>
    <portlet-info>
        <title>myportlet</title>
    </portlet-info>
</portlet>

i want from the client side (by javascript) to get the render html portlet and also all it's params and included files?

1

1 Answers

1
votes

Not a clean way, but i am not aware about anything else.

There's something called as widget URL.

you get it via any portlet's configuration.

enter image description here

Now load this URL in an iFrame. you will achieve your objective of loading the protlet without refreshing the page.

here's some sample snippet.

window.Liferay = window.Liferay || {};

Liferay.Widget = function(options) {
    options = options || {};

    var id = options.id || '_Liferay_widget'
            + (Math.ceil(Math.random() * (new Date).getTime()));
    var height = options.height || '100%';
    var url = options.url
            || 'http://www.liferay.com/widget/web/guest/community/forums/-/message_boards';
    var width = options.width || '100%';

    var html = '<iframe frameborder="0" height="' + height + '" id="' + id
            + '" src="' + url + '" width="' + width + '"></iframe>';
    return html;
}