掲示板

Workaround portal-impl.jar classes constructor

7年前 に Sourabh Lonikar によって更新されました。

Workaround portal-impl.jar classes constructor

Junior Member 投稿: 42 参加年月日: 16/11/14 最新の投稿
Hi all,
I am getting error while using classes from portal-impl.jar inside my custom portlet. From Need to call a portal-impl method thread, it seems we cannot reference such classes within custom portlet.

From thread Need to call a portal-impl method, I have followed correct solution provided by Nicolas Mugnier.

I am having issue in applying this solution to my requirement which is :

My Code:
ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();
Class<?> liferayFileEntryClass = portalClassLoader.loadClass("com.liferay.portal.repository.liferayrepository.model.LiferayFileEntry");
Constructor<?> c = liferayFileEntryClass.getDeclaredConstructor(DLFileEntry.class);
Object liferayFileEntry = c.newInstance(dlFileEntry);

dlAppHelperLocalService.updateAsset(userId, liferayFileEntry, liferayFileVersion, assCa, assetTagNames, serviceContext.getAssetLinkEntryIds());

Nicolas's Solution:

ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();
Class<?> portletRendererClass = portalClassLoader.loadClass("com.liferay.portal.layoutconfiguration.util.PortletRenderer");
Constructor<?> c = portletRendererClass.getDeclaredConstructor(com.liferay.portal.model.Portlet.class,
String.class, Integer.class, Integer.class);
Object portletrendererobject = c.newInstance(portlet, columnId, columnCount, columnPos);
Method method = portletrendererobject.getClass().getMethod("render", HttpServletRequest.class, HttpServletResponse.class);
StringBundler _result = (StringBundler) method.invoke(portletrendererobject, request, response);


Nicolas's solution works for him since he only uses method and skips object as method parameter.

Problem Statement:
1. dlAppHelperLocalService.updateAsset() expects LiferayFileEntry object while I end up sharing Object which is in conflict with method signature.
2. Is there any static instanciation service provider not residing in portal-impl.jar ?

Can someone suggest workaround for same since portal-impl.jar classes must be used in many places.


Regards,
Sourabh
7年前 に Sourabh Lonikar によって更新されました。

RE: Workaround portal-impl.jar classes constructor (回答)

Junior Member 投稿: 42 参加年月日: 16/11/14 最新の投稿
Fortunately all these portal-impl.jar classes seem to implement interfaces residing in portal-services.jar.

Hence I just refer those object references by their interfaces. Not sure if this will work in all cases, but it is working for me.

Thanks,
Sourabh
thumbnail
7年前 に Samuel Kong によって更新されました。

RE: Workaround portal-impl.jar classes constructor

Liferay Legend 投稿: 1902 参加年月日: 08/03/10 最新の投稿
Hi Sourabh,

You're correct in using the classes in portal-services.jar. portal-impl.jar is the portal's private API and you should never reference classes in portal-impl.jar from your custom portlets.