掲示板

liferay.fire

7年前 に sunny huang によって更新されました。

liferay.fire

Junior Member 投稿: 56 参加年月日: 11/01/17 最新の投稿
Hello. I would like to know how the liferay.fire () work?
I looked at the document_library portlet, in its sort_button.jsp has the following code:
<aui:nav-item dropdown="<%= true %>" id="sortButtonContainer" label="sort-by">

	&lt;%
	String taglibURL = "javascript:" + liferayPortletResponse.getNamespace() + "sortEntries('" + folderId + "', 'title','" + reverseOrderByType + "')";
	%&gt;

	<aui:nav-item href="<%= taglibURL %>" label="title" />

	&lt;%
	taglibURL = "javascript:" + liferayPortletResponse.getNamespace() + "sortEntries('" + folderId + "', 'creationDate','" + reverseOrderByType + "')";
	%&gt;

	<aui:nav-item href="<%= taglibURL %>" label="create-date" />

	&lt;%
	taglibURL = "javascript:" + liferayPortletResponse.getNamespace() + "sortEntries('" + folderId + "', 'modifiedDate','" + reverseOrderByType + "')";
	%&gt;

	<aui:nav-item href="<%= taglibURL %>" label="modified-date" />

	&lt;%
	taglibURL = "javascript:" + liferayPortletResponse.getNamespace() + "sortEntries('" + folderId + "', 'downloads','" + reverseOrderByType + "')";
	%&gt;

	<aui:nav-item href="<%= taglibURL %>" label="downloads" />

	&lt;%
	taglibURL = "javascript:" + liferayPortletResponse.getNamespace() + "sortEntries('" + folderId + "', 'size','" + reverseOrderByType + "')";
	%&gt;

	<aui:nav-item href="<%= taglibURL %>" label="size" />
</aui:nav-item>

You can see the taglibURL call the JSP file in the <aui:script> function:

<aui:script>
	Liferay.provide(
		window,
		'<portlet:namespace />sortEntries',
		function(folderId, orderByCol, reverseOrderByType) {
			Liferay.fire(
				'<portlet:namespace />dataRequest',
				{
					requestParams: {
						'<portlet:namespace />folderId': folderId,
						'<portlet:namespace />navigation': '&lt;%= HtmlUtil.escape(navigation) %&gt;',
						'<portlet:namespace />struts_action': '/document_library/view',
						'<portlet:namespace />fileEntryTypeId': &lt;%= fileEntryTypeId %&gt;,
						'<portlet:namespace />viewEntries': &lt;%= Boolean.FALSE.toString() %&gt;,
						'<portlet:namespace />viewEntriesPage': &lt;%= Boolean.TRUE.toString() %&gt;,
						'<portlet:namespace />viewFolders': &lt;%= Boolean.FALSE.toString() %&gt;,
						'<portlet:namespace />orderByCol': orderByCol,
						'<portlet:namespace />orderByType': reverseOrderByType,
						'<portlet:namespace />saveOrderBy': &lt;%= Boolean.TRUE.toString() %&gt;
					}
				}
			);
		},
		['aui-base']
	);
</aui:script>

This code in the document_library portlet can be a good implementation of the jump, if I put the sort_button.jsp include to document_library_display in this portlet, the jump will not respond.
Liferay.fire (), what is the implementation of the mechanism? Where to set up listening?
(read the official document , there is no detailed description, that is Liferay.fire, Liferay.on two functions, a trigger, a listener, but do not know where to set and find
Thank you
thumbnail
6年前 に David H Nebinger によって更新されました。

RE: liferay.fire

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
It's basically a JS implementation of a browser-side eventing mechanism.

Through Liferay.fire() you can trigger an 'event'. Through Liferay.on() you can register an event listener which should do something to handle the event. The on() side will maintain the list of listeners for each event so one fire can trigger zero or more event listeners depending upon what has been registered.

Normally this kind of thing is implemented as a form of portlet IPC so two portlets can be detached from each other but still effect each other in the browser. Think of a list and detail portlets on a page; the list will send an event any time the selected item changes and the detail listens for the event and updates it's display based on the selected value. Display might also fire events back to the list if user can make changes to the title so list can be updated to reflect the change.







Come meet me at the 2017 LSNA!
thumbnail
6年前 に Amos Fong によって更新されました。

RE: liferay.fire

Liferay Legend 投稿: 2047 参加年月日: 08/10/07 最新の投稿
One caveat on Liferay 7 I ran into(not sure if this is a bug in Senna?), because pages don't reload completely anymore with Senna, your javascript events will start to accumulate each page change and may execute your function multiple times on when the js event is fired.
thumbnail
6年前 に Chema Balsas によって更新されました。

RE: liferay.fire

Regular Member 投稿: 127 参加年月日: 13/02/25 最新の投稿
Hey Amos,

The behaviour you mention is the expected one, and it could lead to errors where applications are not properly using the lifecycles to clean after them.

This is explained in the Detaching Global Listeners section of the Automatic Single Page Applications tutorial.
thumbnail
6年前 に Amos Fong によって更新されました。

RE: liferay.fire

Liferay Legend 投稿: 2047 参加年月日: 08/10/07 最新の投稿
That's useful to know, thanks Chema!