Thursday, November 22, 2012

Accesing Portal impl class metods in custom portlet


Some times we need to use portal-impl classes functionality,but we can't access that in our custom portlet. Hence,we require to PortalClassInvoker class.

for example : we need to access PortalLDAPUtil.getLdapServerId()(method for get LDAP ServerId) in our costum portlet and it's there in portal-impl ,so access is the issue. For that , we use PortalClassInvoker.invoke() (This method have many forms) with MethodKey.

Following are steps to use PortalClassInvoker.invoke() method to access utility of portal-impl class PortalLDAPUtil.

1) Initialize MethodKey object.
 
    Syntax : MethodKey portalLDAPUtilMethodKey = new MethodKey("classNameWithPackagePath", "methodName",argClassType1,argClassType2......);
 
    Example : MethodKey portalLDAPUtilMethodKey = new MethodKey("com.liferay.portal.security.ldap.PortalLDAPUtil", "getLdapServerId",Long.class,String.class);
 
2) Use PortalClassInvoker.invoke() to access portal-impl classes using MethodKey.

    Syntax : PortalClassInvoker.invoke(newInstance, methodKey, argumentList);
 
    Example : Long ldapServerId = (Long) PortalClassInvoker.invoke(false, portalLDAPUtilMethodKey, new Object[] {Long.valueOf(themeDisplay.getCompanyId()),screenName});

here screenName is ldap user screenName. i.e. “xyz.abc”.

No comments:

Post a Comment