Montag, 20. Juni 2016

Write preferences globally so you can read anywhere

ServiceContext serviceContext = ServiceContextFactory.getInstance(renderRequest);
PortletPreferences portletPreferences = PrefsPropsUtil.getPreferences(
serviceContext.getCompanyId());
portletPreferences.setValue("key","Value");
portletPreferences.store();

and then read like PropsUtil.get("key");

Dienstag, 26. April 2016

Call AUI script from a liferay ADT

<#assign aui = taglibLiferayHash["/WEB-INF/tld/aui.tld"] />


<@aui["script"]  use='aui-base'>
     var parentNode = A.one(".mainWebContentPortlet");
      parentNode.one(".navbar").setStyle('display', 'none');
   
 </@>

Mittwoch, 30. März 2016

Reading custom attribute from hook Liferay.

Some time you want to read custom attribute from hook or from function which was called by some ajax request. You will get null value when you will try to access these attributes through expand bridge unless you set the permission first.  Some thing similar as given below

final Role adminRole = RoleLocalServiceUtil.getRole(user.getCompanyId(), "Administrator");
final List<User> adminUsers =UserLocalServiceUtil.getRoleUsers(adminRole.getRoleId());
PrincipalThreadLocal.setName(adminUsers.get(0).getUserId());
final PermissionChecker permissionChecker =PermissionCheckerFactoryUtil.create(adminUsers.get(0));

Dienstag, 29. März 2016

Liferay Reflection

MethodKey methodKey =
new MethodKey(ClassResolverUtil.
resolveByPortalClassLoader("com.liferay.portal.util.WebAppPool"),
"get", new Class[]{Long.class,String.class});

PortletCategory portletCategory =(PortletCategory)PortalClassInvoker.invoke(false, methodKey, new Object[] {new Long(user.getCompanyId()),"PORTLET_CATEGORY"});


For custom bean defined in a portlet

Object obj =PortletBeanLocatorUtil.locate("Injector-portlet", "your.portlets.ItemTool");
Class<?> claz = obj.getClass();
Object instance = claz.newInstance();
claz.getMethod("methodName").invoke(instance);

Dienstag, 20. Oktober 2015

Liferay refresh portlet with Ajax

function refreshAssetPublisherPortlet() {
   var portletSelector = '.portlet-asset-publisher';
   var refreshInterval = 10000;   
   Liferay.Portlet.refresh(portletSelector);
   setInterval(refreshAssetPublisherPortlet, refreshInterval);
}
refreshAssetPublisherPortlet();

Donnerstag, 6. November 2014

PDF file from Html -->ITextRenderer

If you are using ITextRenderer for pdf creation from Html, then use its method setDocumentFromString(String html) which accepts string. instead of setDocument(Document, String Uri) because SetDocument method need Document as parameter and for that you have to parse html to Document first and standard parse method from DocumentBuilder is very slow.