Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PortletURL to open another portlet in pop-up

I have a hook for create_account.jsp. In this jsp I have a javascript code where I try to open a portlet in an iframe pop-up or some pop-up from Liferay.

The question is:
How to give the portlet URL?
How can I access it?
In that portlet I only want to ask a question with YES or NO, and based on the user answer, redirect to some other page.

like image 385
Any Avatar asked Jan 10 '13 20:01

Any


1 Answers

  1. To create a URL, you can either use <portlet:renderURL> or <liferay-portlet:renderURL>

    <liferay-portlet:renderURL
        var="testPopupURL"
        portletName="testPopup_WAR_testPopupportlet"
        windowState="<%=LiferayWindowState.POP_UP.toString() %>">
        <liferay-portlet:param name="paramToPopup" value="customParameterToThePortlet" />
    </liferay-portlet:renderURL>
    

    portletName="testPopup_WAR_testPopupportlet" this is the portletId of the portlet which you want to open.

    windowState="<%=LiferayWindowState.POP_UP.toString() %>" This is important to just show the portlet in the pop-up, or else it would open the full liferay pages with navigation and all.

  2. The javascript which you can write in your JSP to use the above URL and open the popup and the portlet within:

    // this is one of creating function
    function <portlet:namespace />showPopup(url) {
    
        var url = url;
    
        // this is one way of calling a pop-up in liferay
        // this way is specific to liferay
        Liferay.Util.openWindow(
                {
                    dialog: {
                        cache: false,
                        width:800,
                        modal: true
                    },
                    id: 'testPopupIdUnique',                
                    uri: url
                }
            );
        }
    
    // this is another way of creating a function in liferay
    Liferay.provide(
            window,
            '<portlet:namespace />showAUIPopUP',
            function(url) {
                var A = AUI();
    
                // this is another way of calling a iframe pop-up
                // this way is not specific to liferay
                popupDialog = new A.Dialog(
                    {
                        id: 'testPopupIdUnique',
                        centered: true,
                        draggable: true,
                        resizable: true,
                        width: 800,
                        stack: true
                    }
                ).plug(
                    A.Plugin.DialogIframe,
                    {
                        uri: url,
                        iframeCssClass: 'ogilvy-dialog-iframe'
                    }
                );
    
                popupDialog.render();
            },
        ['aui-dialog','aui-dialog-iframe']
    );
    
  3. You can simply call these javascript functions something like this:

    <a href="javascript: <portlet:namespace />showPopup('<%=testPopupURL%>')">
        Popup using Liferay open-window
    </a>
    
    <a href="javascript: <portlet:namespace />showAUIPopUP('<%=testPopupURL%>')">
        Pop-up using Alloy UI dialog
    </a>
    
  4. The portlet which would be displayed inside the iframe of the pop-up either should have <add-default-resource>true</add-default-resource> in liferay-portlet.xml as:

    <portlet>
        <portlet-name>testPopup</portlet-name>
        <icon>/icon.png</icon>
        <instanceable>false</instanceable>
        <header-portlet-css>/css/main.css</header-portlet-css>
        <footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
        <css-class-wrapper>testPopup-portlet</css-class-wrapper>
        <!-- This property is necessary otherwise you would see a "Access denied for portlet" message when you try to open this portlet dynamically -->
        <add-default-resource>true</add-default-resource>
    </portlet>
    
  5. Or should have the property portlet.add.default.resource.check.whitelist in portal-ext.properties as:

    portlet.add.default.resource.check.whitelist=3,56_INSTANCE_0000,58,82,86,87,88,103,113,145,164,166,170,177,testPopup_WAR_testPopupportlet
    

To check out this code in action you can download 2 portlets from and refer to the instructions in this liferay forum.

Hope this helps in understanding liferay better.

like image 51
Prakash K Avatar answered Sep 23 '22 02:09

Prakash K