Friday 18 May 2012

How to determine is there a portlet on page

Hello,
    If you want to know how define is there a portlet on page, check this post.

    When you are adding portlet on the page and portlet is not instanceable. You will not be able to add it twice.


      As you can see Sign in portlet already present at page and you can add it second time. Somehow Liferay checks has page this portlet or not. I was interested how it works.
  
      First I found javascript which serves this portlets menu, it's located:
              /portal/portal-web/docroot/html/js/liferay/layout_configuration.js,
      line 205 - _addPorletMethod, inside of it there is second method - _disablePortletEntry which manipulates some css class - lfr-portlet-used.
  
     After serching this class over sources I found:
             /portal/portal-web/docroot/html/portlet/layout_configuration/view_category.jsp,
    which generates portlets menu. It has next code which helps to define is there portlet at page:

      boolean portletUsed = layoutTypePortlet.hasPortletId(portlet.getPortletId());
   
    By this value  lfr-portlet-used css class which makes menu item disabled will be added to div:

">lfr-portlet-used lfr-instanceable" id="portletItem<%= portlet.getPortletId() %>" instanceable="<%= portletInstanceable %>" plid="<%= plid %>" portletId="<%= portlet.getPortletId() %>" title="<%= PortalUtil.getPortletTitle(portlet, application, locale) %>" >

<%= PortalUtil.getPortletTitle(portlet, application, locale) %>


BR,
Paul

No comments:

Post a Comment