Fórumok

Call serveResource() method of Portlet A from Portlet B

thumbnail
Raja Seth, módosítva 9 év-val korábban

Call serveResource() method of Portlet A from Portlet B

Regular Member Bejegyzések: 233 Csatlakozás dátuma: 2011.08.18. Legújabb bejegyzések
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
David H Nebinger, módosítva 9 év-val korábban

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

Liferay Legend Bejegyzések: 14914 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
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
Raja Seth, módosítva 9 év-val korábban

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

Regular Member Bejegyzések: 233 Csatlakozás dátuma: 2011.08.18. Legújabb bejegyzések
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
David H Nebinger, módosítva 9 év-val korábban

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

Liferay Legend Bejegyzések: 14914 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
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
Raja Seth, módosítva 9 év-val korábban

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

Regular Member Bejegyzések: 233 Csatlakozás dátuma: 2011.08.18. Legújabb bejegyzések
Hi David,

I agree with your point. Thanks David for your reply

Thanks,
Raja
thumbnail
Nikhil Nishchal, módosítva 9 év-val korábban

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

Regular Member Bejegyzések: 174 Csatlakozás dátuma: 2012.06.22. Legújabb bejegyzések
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
Raja Seth, módosítva 8 év-val korábban

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

Regular Member Bejegyzések: 233 Csatlakozás dátuma: 2011.08.18. Legújabb bejegyzések
Thanks Nikhil for your reply.