Foros de discusión

liferay.fire

sunny huang, modificado hace 7 años.

liferay.fire

Junior Member Mensajes: 56 Fecha de incorporación: 17/01/11 Mensajes recientes
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, modificado hace 6 años.

RE: liferay.fire

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
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, modificado hace 6 años.

RE: liferay.fire

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
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, modificado hace 6 años.

RE: liferay.fire

Regular Member Mensajes: 127 Fecha de incorporación: 25/02/13 Mensajes recientes
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, modificado hace 6 años.

RE: liferay.fire

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
That's useful to know, thanks Chema!