Search

Wednesday, September 16, 2009

Getting list of portlet in existing Layout.

Layout layoutForPortletName = LayoutLocalServiceUtil.getLayout(plidSelected);

LayoutTypePortlet layoutTypePortletName = (LayoutTypePortlet)layoutForPortletName.getLayoutType();

LayoutTemplate layoutTemplate=layoutTypePortletName.getLayoutTemplate();

List columnCount = layoutTemplate.getColumns();

for(int i=0; i
String column = columnCount.get(i);
List portlets = layoutTypePortletName.getAllPortlets(column);

for(Portlet portlet : portlets){

PluginPackage pluginPackage = portlet.getPluginPackage();
PluginSetting pluginSetting = PluginSettingLocalServiceUtil.getPluginSetting(company.getCompanyId(), portlet.getPortletId(), Plugin.TYPE_PORTLET);

StringBuilder sb = new StringBuilder();

String displayName = portlet.getDisplayName();
String title = PortalUtil.getPortletTitle(portlet, application, locale);

out.println("portletId = "+portlet.getPortletId()+" "+" Title = " +title);


}
out.println("");
}

Getting a ServletContext instance from a Portlet

Sometime when developing a portlet you need to access the ServletContext object. Both JSR, 168 and 286, doesn't provide a generic way to access it. To solve this issue Liferay offers a class called com.liferay.portal.kernel.portlet.PortletBag that enables you to access the ServletContext through its method called getServletContext(). To get a instance of PortletBag you should use the com.liferay.portal.kernel.portlet.PortletBagPool class like the snippet:


String portletId = "your-portlet-id";
PortletBag portletBag = PortletBagPool.get(portletId);
ServletContext servletContext = portletBag.getServletContext();

Monday, September 14, 2009

How to get public and private Layouts in Liferay

Group group = themeDisplay.getScopeGroup();

group = GroupLocalServiceUtil.getGroup(group.getGroupId());

int layoutCount = LayoutLocalServiceUtil.getLayoutsCount();

// Public Layout
List allLayouts = LayoutLocalServiceUtil.getLayouts(group
.getGroupId(), false);
// Private Layout
List allLayouts1 = LayoutLocalServiceUtil.getLayouts(group
.getGroupId(), true);

How to get list of portlets in Liferay

List portlets = PortletLocalServiceUtil.getPortlets(company.getCompanyId(), false, false);
//portlets = ListUtil.sort(portlets, new PortletTitleComparator(application, locale));
int total = portlets.size();
for (int i = 0; i < total; i++) {
Portlet portlet = portlets.get(i);

PluginPackage pluginPackage = portlet.getPluginPackage();
PluginSetting pluginSetting = PluginSettingLocalServiceUtil.getPluginSetting(company.getCompanyId(), portlet.getPortletId(), Plugin.TYPE_PORTLET);

// Name and description

StringBuilder sb = new StringBuilder();

String displayName = portlet.getDisplayName();
String title = PortalUtil.getPortletTitle(portlet, application, locale);

}