留言板

liferay.fire

sunny huang,修改在7 年前。

liferay.fire

Junior Member 帖子: 56 加入日期: 11-1-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
David H Nebinger,修改在6 年前。

RE: liferay.fire

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
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
Amos Fong,修改在6 年前。

RE: liferay.fire

Liferay Legend 帖子: 2047 加入日期: 08-10-7 最近的帖子
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
Chema Balsas,修改在6 年前。

RE: liferay.fire

Regular Member 帖子: 127 加入日期: 13-2-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
Amos Fong,修改在6 年前。

RE: liferay.fire

Liferay Legend 帖子: 2047 加入日期: 08-10-7 最近的帖子
That's useful to know, thanks Chema!