掲示板

Call serveResource() method of Portlet A from Portlet B

thumbnail
9年前 に Raja Seth によって更新されました。

Call serveResource() method of Portlet A from Portlet B

Regular Member 投稿: 233 参加年月日: 11/08/18 最新の投稿
Hi All,

I have two portlets(Portlet A & Portlet emoticon. Considering Portlet A as a core portlet, I have written serveResource() method in Portlet A. Now I want to call this serve resource method from Portlet B. When I am trying to call the serveResource() method of Portlet A from Portlet B it's not getting called.

I have entry in jsp of portlet as below :

<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="theme" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>

<div class="my-performance-content" id="myPerformanceContent"></div>

<liferay-portlet:resourceurl var="CorePortletResourceUrl" portletname="portlet_core_WAR_coreportlet"></liferay-portlet:resourceurl>

window.onload=function() {
	//alert("CorePortletResourceUrl : &gt; "+CorePortletResourceUrl);
	AUI().ready('aui-io-request',function(A) {
		A.io.request('&lt;%=CorePortletResourceUrl%&gt;',{
			method : 'POST',
			dataType : 'json',
			data : {
				<portlet:namespace />cmd : "onLoad",
			},
			on : {
				success : function() {
					$("#myPerformanceContent").empty();
					
					var responseData = this.get('responseData');
					$("#myPerformanceContent").append(responseData);
				},
				failure : function() {
				}
			}
		});
	});
};


Please let me know if anything else I am missing in the above code or is there any other approach to resolve it.

Thanks & Regards,
Raja
thumbnail
9年前 に David H Nebinger によって更新されました。

RE: Call serveResource() method of Portlet A from Portlet B

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
Why did you need to add resource handler to a core portlet? If you have your own portlet, it has access to all portal resources internally, so this whole premise really doesn't make a lot of sense...
thumbnail
9年前 に Raja Seth によって更新されました。

RE: Call serveResource() method of Portlet A from Portlet B

Regular Member 投稿: 233 参加年月日: 11/08/18 最新の投稿
Hi David,

Thanks for the reply. Actually I would be accessing this serveResource() method from multiple portlets to achieve some functionality and I already have core portlet which includes all the services required in other portlets. So it's better to have one serveResource() instead on having on multiple portlets.

I am able to call serve resource method now but I am not able to get the param which I am passing it :

data : {
<portlet:namespace />cmd : "onLoad",
},

or

data : {
cmd : "onLoad",
},

Please suggest the solution for it.

Thanks,
Raja
thumbnail
9年前 に David H Nebinger によって更新されました。

RE: Call serveResource() method of Portlet A from Portlet B (回答)

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
Raja Seth:
So it's better to have one serveResource() instead on having on multiple portlets.


I would argue against that point. Yes it is best to reuse code, reuse web services, etc. But a portlet URL? No, I think not.

The problem is it introduces tight coupling on portlets, something that a portal in general was designed to avoid.

Since to use the resource url you have to have the target on the page, anywhere your portlet(s) are going to need the resource this other portlet must also be placed.

And, if for whatever reason, you change the resource url specification, you have to go back and fix/redeploy all dependent portlets.

It really makes absolutely no sense.

It is quite easy to create a resource handler in each portlet and have them invoke shared code (either by SB or some other appropriate mechanism). It adds zero overhead and avoids this tight coupling and dependencies. Your concept must be avoided, pretty much at all costs.
thumbnail
9年前 に Raja Seth によって更新されました。

RE: Call serveResource() method of Portlet A from Portlet B

Regular Member 投稿: 233 参加年月日: 11/08/18 最新の投稿
Hi David,

I agree with your point. Thanks David for your reply

Thanks,
Raja
thumbnail
9年前 に Nikhil Nishchal によって更新されました。

RE: Call serveResource() method of Portlet A from Portlet B

Regular Member 投稿: 177 参加年月日: 12/06/22 最新の投稿
For the reason, if you need to add resource URL of one portlet in another.

You can add it to any page and then using that plid and portlet name you can call its resouce url from another portlet.

Pros of this way:
you can use common functionality from one place.
Change in that common functionality you need to deploy only one common portlet (till resource url is same).

Cons of this way:
You need to be dependent to that page and portlet, so that resource URL should not be change.
Otherwise need to change it in all portlet.
You may make it configurable to select that page or portlet name.
thumbnail
9年前 に Raja Seth によって更新されました。

RE: Call serveResource() method of Portlet A from Portlet B

Regular Member 投稿: 233 参加年月日: 11/08/18 最新の投稿
Thanks Nikhil for your reply.