Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: MVC ResourceCommand Not working for Calendar Portlet (Out-of-Box)
Hi ,
I m trying to implement MVC ResourceCommand for outofbox Calendar Portlet in liferay7.0 GA5. But its not working ,Could you please let me know in case i missed something .
Module deployed and started successfully but I'm not able to se changes
My I'm trying to override existing serverresource method of calendar portlet.
@Component( immediate = true, property = {"javax.portlet.name=com_liferay_calendar_web_portlet_CalendarPortlet", "mvc.command.name=calendarRenderingRules", "service.rank=100000" }, service = MVCResourceCommand.class ) public class CalendarPortletAction implements MVCResourceCommand{ @Override public boolean serveResource (ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws PortletException { System.out.println (">>>>>>>>>>>>> before"); String resourceID = GetterUtil.getString (resourceRequest.getResourceID ()); String cmd = ParamUtil.getString (resourceRequest, "autoComplete"); String searchKey = ParamUtil.getString (resourceRequest, "searchKey"); System.out.println (">>> after"); return mvcResourceCommand.serveResource (resourceRequest, resourceResponse); } protected MVCResourceCommand mvcResourceCommand; }BND FIle
Bundle-Name: calendar-mvc-command Bundle-SymbolicName: calendar.web.portlet Bundle-Version: 1.0.0
=====================================================================================================
Please let me know in case of any other best approach to override server resource method in liferay 7.0 Calendar Portlet Class
@Override @Component( immediate = true, property = { "com.liferay.portlet.add-default-resource=true", "com.liferay.portlet.css-class-wrapper=calendar-portlet", "com.liferay.portlet.display-category=category.collaboration", "com.liferay.portlet.friendly-url-mapping=calendar", "com.liferay.portlet.header-portlet-css=/css/main.css", "com.liferay.portlet.icon=/icons/calendar.png", "com.liferay.portlet.preferences-owned-by-group=true", "com.liferay.portlet.preferences-unique-per-layout=false", "javax.portlet.display-name=Calendar", "javax.portlet.expiration-cache=0", "javax.portlet.init-param.copy-request-parameters=true", "javax.portlet.init-param.view-template=/view.jsp", "javax.portlet.name=" + CalendarPortletKeys.CALENDAR, "javax.portlet.resource-bundle=content.Language", "javax.portlet.security-role-ref=administrator,guest,power-user,user", "javax.portlet.supports.mime-type=text/html" }, service = Portlet.class ) public class CalendarPortlet extends MVCPortlet { public void serveResource( ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws PortletException { try { String resourceID = resourceRequest.getResourceID(); if (resourceID.equals("calendar")) { serveCalendar(resourceRequest, resourceResponse); } else if (resourceID.equals("calendarBookingInvitees")) { serveCalendarBookingInvitees(resourceRequest, resourceResponse); } else if (resourceID.equals("calendarBookings")) { serveCalendarBookings(resourceRequest, resourceResponse); } else if (resourceID.equals("calendarBookingsRSS")) { serveCalendarBookingsRSS(resourceRequest, resourceResponse); } else if (resourceID.equals("calendarRenderingRules")) { serveCalendarRenderingRules(resourceRequest, resourceResponse); } else if (resourceID.equals("calendarResources")) { serveCalendarResources(resourceRequest, resourceResponse); } else if (resourceID.equals("currentTime")) { serveCurrentTime(resourceRequest, resourceResponse); } else if (resourceID.equals("exportCalendar")) { serveExportCalendar(resourceRequest, resourceResponse); } else if (resourceID.equals("resourceCalendars")) { serveResourceCalendars(resourceRequest, resourceResponse); } else { serveUnknownResource(resourceRequest, resourceResponse); } } catch (Exception e) { throw new PortletException(e); } } }
Check out the docs if you haven't already:
https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/overriding-mvc-commands
I think what you're missing is to add a service.ranking to your component so it takes precedence over the original MVCCommand.
Amos Fong<p>Check out the docs if you haven't already:</p>
<p>
<a href="https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/overriding-mvc-commands">https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/overriding-mvc-commands</a></p>
<p> </p>
<p>I think what you're missing is to add a service.ranking to your
component so it takes precedence over the original MVCCommand.</p>
I have add service.ranking but still same issue
What are you trying to achieve? maybe it can be done another way?
Amos FongI looked up calendarRenderingRules and it doesn't look like there is a MVCResourceCommand for it so you can't override this way. It's implemented in CalendarPortlet.servceResource() and I don't think you can override the CalendarPortlet via service.rankings AFAIK.
What are you trying to achieve? maybe it can be done another way?
Thanks for reply. Could you please let us know way to overiride CalendarPortlet in Liferay 7 DXP
and How to add mvcResourceCommand Method for CalendarPortlet
Both MVCActionCommand and MVCRenderCommand are working fine except MVCResourceCommand in Calendar Portlet, I have tried in multiple ways but MVCResourceCommand not working in CalendarPortet
The reason is that unfortunately CalendarPortlet.java has completely overrided MVCPortlet.java/LiferayPortlet.java's serveResource method. The original serviceResource method works as:
- it checks if the resource ID is in the MVCResourceCommand list of the portlet- if not, it uses the resourceID to find the method by reflection.
But in CalendarPortlet.java, as the source codes listed in the very first post, it only checks if the resource id is one of "calendar", "calendarBookingInvitees" ..."calendarBookings" etc and never calls 'super.serveResource'. Therefore the portlet will never check your customized MVCResourceCommand. So one can not add new resource id by simply create a new MVCResourceCommand.
Powered by Liferay™