Using Pop-up in Liferay

When developing portlets in Liferay there are two ways to implement pop-ups. We can use a Floating Div or the traditional new browser Window without the toolbars. Each of them has got their advantages so we will have to decide which one fits us better. For example, if you are using a pop up with a form, you won't be able to send files attached to the form if you are using a floating div.

In this article there are some tips to develop both types of pop-ups.

Floating Div Pop-Up #

Liferay provides a class called Expanse.Popup to implement this type of pop ups. Here is how this type of pop up would look like:

One advantage of this type of pop up is that they are invisible to pop up blockers (although that could change as they get smarter). This javascript code will make an asynchronous call to the url we give it and will place the content in our page. Below there is an example which will load the url 'url' in a pop up called 'our title':

var popup = new Expanse.Popup(
				{
					header: 'our title',
					position:[150,150],
					modal:true,
					width:500,
					height:300,
					xy: ['center', 100],
					url: 'url',
					urlData: {
						parameter1: 'value1',
                                                parameter2: 'value2'
					}
				}
			);

It's important to note that if the url is a portlet url it must have the windowState parameter set to LiferayWindowState.EXCLUSIVE, because we just want the content produced by the portlet and not the extra portlet decoration produced by the portal.

To implement a button or link to close the pop up use the following code:

Expanse.Popup.close(this);

This type of pop-up is used in several Liferay core portlets like the image gallery (show pictures), journal (edit template) or my communities (publish to live). Look at them for further examples of usage.

Window Pop up #

This type of pop ups will load in a new window. In order to do that we must set the windowState parameter in the portlet url to LiferayWindowState.POP_UP. This windowState will produce that the result of calling a portlet url will be shown in another window, like a real pop up. There are no visual effects asociated, it's a different window.

However, from this window we can still make javascript calls to the parent page javascript functions as the javascript object opener refers to the parent window. There is an example below:

<input type="button" value="select" onClick="
	var organizationWindow = window.open('
			<portlet:renderURL 
				windowState="<%= LiferayWindowState.POP_UP.toString() %>">
				<portlet:param name="struts_action" value="/enterprise_admin/select_organization" />
		 		<portlet:param name="tabs1" value="organizations" />
			</portlet:renderURL>',
			 'title',
			'directories=no, height=640, location=no, menubar=no, resizable=yes, 
                                                                               scrollbars=yes, status=no, toolbar=no, width=680');
	 
	organizationWindow.focus();" />

If we want to close the pop up we just need to do the following:

 window.close(); 

If we want to close the parent page we can do the following:

opener.close(); 

This is used in several portlets like the image gallery (show slideShow), enterprse admin (select organizations for users...)

Floating Div Pop-up in 6.1 #

In 6.1, Liferay uses pop-ups extensively. Here is the code you can simply put in your jsp to load a portlet or any other content asynchronously (Ajax) using Alloy.

<aui:script>

Liferay.provide(
	window,
	'showSiteManagement',
	function() {
		var A = AUI(); 	
		var portletURL="<%= themeDisplay.getURLManageSiteMemberships().toString() %>";
		var dialog = new A.Dialog(
			{
				destroyOnClose: true,
				modal: false,
				title: 'My title',
				width: 900
			}
		).plug(
			A.Plugin.IO,
				{
					uri: portletURL.toString()
				}
		).render();
	},
	['aui-dialog']
); 
</aui:script>

Now, making a simple javascript call to the "showSiteManagement()" will open a floating window and load in the portles content. However as you will see, this does not work so very well if your portlet has actions and url. Any action/urls will result in reload of the whole page.

For those cases Liferay has another tool witch opens an IFrame inside the Alloy Dialog. The result looks the same however it works much better for displaying portlets and such.

<aui:script>
	Liferay.provide(
		window,
		'showSiteManagement',
		function() {
			var instance = this;

			var url='<%= themeDisplay.getURLManageSiteMemberships().toString() %>';

				Liferay.Util.openWindow(
					{
						cache: false,
						dialog: {
							align: Liferay.Util.Window.ALIGN_CENTER,
							after: {
								render: function(event) {
									this.set('y', this.get('y') + 50);
								}
							},
							width: 820
						},
						dialogIframe: {
							id: 'siteManagementIframe',
							uri: url
						},
						title: 'Site Management',
						uri: url
					}
				);
		},
		['liferay-util-window']
	);
	</aui:script>

In both cases I have used the "themeDisplay.getURLManageSiteMemberships().toString()" to get the URL to the portlet. However this code can be used to render a JSP page.

<portlet:renderURL var="somePageURL" windowState="<%= LiferayWindowState.POP_UP.toString() %>">
	<portlet:param name="jspPage" value="/jsp/some/page.jsp"/>
	<portlet:param name="redirect" value="<%= currentURL %>"/>
</portlet:renderURL>

Or this to render another portlet, you can generate an URL like this :

		var url = Liferay.PortletURL.createRenderURL();
                url.setPortletId("3");
                url.setWindowState("pop_up");

PS! In this last code : 1) Not all portlets can be viewed without being white-listet. 2) To use createRenderURL, you must add this 'liferay-portlet-url' to the last parameter of Liferay.provide

2 添付ファイル
172348 参照数
平均 (3 投票)
平均評価は3.3333333333333335星中の5です。
コメント
コメント 作成者 日時
In Liferay-trunk at revision 33901 "Expanse" is... Oliver Bayer 2009/07/23 5:45
Looks like it was renamed again and in my case... Alexey Kakunin 2009/09/19 7:12
Sorry - Liferay.Popup - rest of attributes... Alexey Kakunin 2009/09/19 7:12
This mechanism doesn't work with IceFaces... Alex Wallace 2010/01/25 10:56
After playing with it, loading via ajax is an... Alex Wallace 2010/01/25 11:58
Hi, Can you tell me how can I display a pop-up... Madhura Raut 2011/01/18 21:16
hi Bozhidar Dedov 2012/09/03 4:15
Hi, how could I show a jsp page in popup? I... Mahdi Lashkari 2012/09/29 6:32
Hi Alex I am having the same issue I... dominick campbell 2013/02/26 6:01
i did liferay popup and how do i can localize... delang j 2010/05/09 23:42
can anyone tell me how can i use the code???... ankit yakkundi 2010/08/27 4:22
Hi Ankit, You can create a jsp which will... Faris Abdulla 2010/09/06 8:38
hi, i try using Liferay.popup and... Brahim TARNAOUI 2011/01/12 10:04
hi, In Liferay-trunk at revision 33901... Madhura Raut 2011/01/18 21:14
Here it is what I've done to render a jsp page... Riccardo Rotondo 2013/08/07 7:09
I know this thread is quite old but maybe this... Luca Bacco 2014/11/08 0:29
Hi newbie here how am i supposed to run... Edgar Trania 2013/12/22 18:12
Hi, in the jsp page where the button is... Riccardo Rotondo 2014/02/04 1:50

In Liferay-trunk at revision 33901 "Expanse" is renamed to "Alloy" (LPS-3987).
So to use the "Popup"-function in trunk you must change "new Expanse.Popup" to "new Alloy.Popup()"
投稿日時:09/07/23 5:45
Looks like it was renamed again and in my case (Liferay 5.2.3) I had to use Liferay.POPUP to make it working
Oliver Bayerへのコメント。投稿日時:09/09/19 7:12
Sorry - Liferay.Popup - rest of attributes looks like stay same
Alexey Kakuninへのコメント。投稿日時:09/09/19 7:12
This mechanism doesn't work with IceFaces portlets.

For one, IceFaces portlet don't wokr (actions don't work) when using EXCLUSIVE mode.

Second, these popups use Ajax to load their content and this breaks IceFaces as well... I wish there was an option to not use Ajax to load the content of the floating div popup.

I will have to look for other Floating divs that don't...

Thanks!
投稿日時:10/01/25 10:56
After playing with it, loading via ajax is an option, commonly seen in liferay, where originally message is set to a div with a loading animation, and then jQuery.ajax is used to insert the portlet action url...

If instead, the message is substituted with an iframe that has as src the url where my IceFaces portlet exists, it works...

However the theme displays completly, not just the portlet... I've customized the theme to only show the portlet and nothing else conditionally via http params.. That way the whole thing seems to work: IceFaces portlet in a Liferay.Popup.
Alex Wallaceへのコメント。投稿日時:10/01/25 11:58
i did liferay popup and how do i can localize it content.
thanks.
投稿日時:10/05/09 23:42
can anyone tell me how can i use the code???
can i get the source code which i can copy into view.jsp. do need to create another jsp portlet ,whose content will be displayed on the popup??? if yes then how can show the portlet in popup and how to use the above code ie Floating Div Pop-Up .
delang jへのコメント。投稿日時:10/08/27 4:22
Hi Ankit,

You can create a jsp which will display your details. No need to create a portlet.
1) Create a jsp.
2) Configure struts-config.xml and tiles-defs.xml for rendering the jsp.
3) Create a renderURL for calling the JSP inside your popup.
4) Paste the javascript function in your current jsp. Replace the 'url' with your renderURL.
ankit yakkundiへのコメント。投稿日時:10/09/06 8:38
hi,

i try using Liferay.popup and Expanse.popup but no of this not work.
i'm using Liferay 6.0.5
can you help me please?
Faris Abdullaへのコメント。投稿日時:11/01/12 10:04
hi,
In Liferay-trunk at revision 33901 "Expanse" is renamed to "Alloy" (LPS-3987).
So to use the "Popup"-function in trunk you must change "new Expanse.Popup" to "new Alloy.Popup()" (as commented by Oliver Bayer)
Brahim TARNAOUIへのコメント。投稿日時:11/01/18 21:14
Hi,
Can you tell me how can I display a pop-up with dynamic data on it? I am using Liferay 6.0.4 with JSF 2.0(without ice-faces) and glassfish server v2.1.1
Alex Wallaceへのコメント。投稿日時:11/01/18 21:16
Hi, how could I show a jsp page in popup? I have a jsp in my portlet for example test.jsp and I want to show it in popup. please guide me. thanks a lot!
Bozhidar Dedovへのコメント。投稿日時:12/09/29 6:32
Hi Alex I am having the same issue

I understand how you suppressed the theme to only show the portlet using http params

but how did you build the liferay url? Here is what I am doing currently:
LiferayPortletURL url = PortletURLFactoryUtil.create(httpRequest, portletId, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);

url.setWindowState(LiferayWindowState.POP_UP);
url.s­etPortletMode(PortletMode.VIEW);

Is this what you used?

Thank you
Alex Wallaceへのコメント。投稿日時:13/02/26 6:01
Here it is what I've done to render a jsp page in the popup (called delete.jsp):

 1
 2 <portlet:renderURL var="deleteURL"
 3    windowState= "<%= LiferayWindowState.POP_UP.toString() %>">
 4<portlet:param name="jspPage" value="/jsps/data/delete.jsp" />
 5       
 6    </portlet:renderURL>
 7   
 8    <liferay-ui:icon image="delete" message="file-entry-delete"
 9                     url="javascript:alertDelete();" />
10   
11    <aui:script use="aui-dialog,aui-overlay-manager">
12       Liferay.provide(
13        window,
14        'alertDelete',
15        function() {
16            var instance = this;
17            var url='${deleteURL}';
18
19                Liferay.Util.openWindow(
20                    {
21                        cache: false,
22                        dialog: {
23                            align: Liferay.Util.Window.ALIGN_CENTER,
24                            after: {
25                                render: function(event) {
26                                    this.set('y', this.get('y') + 50);
27                                }
28                            },
29                            width: 820
30                        },
31                        dialogIframe: {
32                            id: 'deleteIFrame',
33                            uri: url
34                        },
35                        title: Liferay.Language.get('cloud'),
36                        uri: url
37                    }
38                );
39        },
40        ['liferay-util-window']
41    );
42
43    </aui:script>


What I wanted to ask is: how I can make the windows to close? In the first example the author mentioned window.close()
What about the second example? You open with Liferay.Util.openWindow ... Is there anything like Liferay.Util.closeWindow to create a button to close? Any help is appreciated. Thank you.
投稿日時:13/08/07 7:09
Hi newbie here how am i supposed to run Floating Div Pop-up in 6.1 assuming that i have a button to click
投稿日時:13/12/22 18:12
Hi,

in the jsp page where the button is located.

Regards,

Riccardo
Edgar Traniaへのコメント。投稿日時:14/02/04 1:50
I know this thread is quite old but maybe this will be usefull for others...

I've added, in the opener page:

<aui:script>
Liferay.provide(
window,
'closeBookmarkPopup',
function() {

var A = AUI();

A.DialogManager.closeByChild('#popUpID');
},
['aui-base','aui-dialog','aui-d­ialog-iframe']
);
</aui:script>


where popupid is:
Liferay.Util.openWindow(
{
cache: false,
id: 'popUpID',
dialog: {
...

better late than never emoticon
Riccardo Rotondoへのコメント。投稿日時:14/11/08 0:29