简体   繁体   中英

Liferay 6.2 - load portlet from client side

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.

eg

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?

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.

在此处输入图片说明

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM