留言板

get calendar class loader in liferay 7

juan meza,修改在7 年前。

get calendar class loader in liferay 7

Regular Member 帖子: 228 加入日期: 14-1-6 最近的帖子
hi, im trying to migrate a portlet from liferay 6.2 to liferay 7... in this portlet i use the calendar a lot (to add and read events)

i used to get the calendar class loader like this:
String servletContextName = "calendar-portlet";
ClassLoader classLoader = (ClassLoader)com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate(servletContextName, "portletClassLoader");


but this does not work in lifeary 7... because of the modules i guess... how can i get the class loader in liferay 7?
thumbnail
David H Nebinger,修改在7 年前。

RE: get calendar class loader in liferay 7

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
um, rarely do you really need another modules class loader? Perhaps you don't need it at all? Not sure w/o further details.







Come meet me at the 2017 LSNA!
juan meza,修改在7 年前。

RE: get calendar class loader in liferay 7

Regular Member 帖子: 228 加入日期: 14-1-6 最近的帖子
Hi David, thank you... what i want is to get all calendars by groupId... i mean the calendars from the calendar portlet

String servletContextName = "calendar-portlet";
ClassLoader classLoader = (ClassLoader)com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate(servletContextName, "portletClassLoader");

// find calendarID via GroupID
// com/liferay/calendar/service/CalendarLocalServiceUtil
com.liferay.portal.kernel.dao.orm.DynamicQuery dynamicQuery = com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil.forClass(com.liferay.calendar.model.Calendar.class, classLoader);
dynamicQuery.add(com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil.forName("groupId").eq(groupId));
java.util.List<com.liferay.calendar.model.calendar> calendars = com.liferay.calendar.service.CalendarLocalServiceUtil.dynamicQuery(dynamicQuery);</com.liferay.calendar.model.calendar>


but when i try to do it i get this exception:
com.liferay.portal.kernel.bean.BeanLocatorException: BeanLocator is not set for servlet context calendar-portlet
at com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate(PortletBeanLocatorUtil.java:46)
at birthdays.portlet.BirthdaysPortlet.getCalendars(BirthdaysPortlet.java:225)


so how do i get the calendars in my site?

thank you!
thumbnail
David H Nebinger,修改在7 年前。

RE: get calendar class loader in liferay 7 (答复)

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
Just use the CalendarLocalServiceUtil.dynamicQuery() method (w/ no params) and you'll get a DQ instance ready for adding your stuff.






Come meet me at the 2017 LSNA!
juan meza,修改在7 年前。

RE: get calendar class loader in liferay 7

Regular Member 帖子: 228 加入日期: 14-1-6 最近的帖子
it works that way! thank you!