Message Boards

MVC ResourceCommand Not working for Calendar Portlet (Out-of-Box)

Testing Test, modified 5 Years ago.

MVC ResourceCommand Not working for Calendar Portlet (Out-of-Box)

New Member Posts: 5 Join Date: 3/26/12 Recent Posts

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);
		}
	}

}

thumbnail
Amos Fong, modified 5 Years ago.

RE: MVC ResourceCommand Not working for Calendar Portlet (Out-of-Box)

Liferay Legend Posts: 2047 Join Date: 10/7/08 Recent Posts

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.

Testing Test, modified 5 Years ago.

RE: MVC ResourceCommand Not working for Calendar Portlet (Out-of-Box)

New Member Posts: 5 Join Date: 3/26/12 Recent Posts
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
thumbnail
Amos Fong, modified 5 Years ago.

RE: MVC ResourceCommand Not working for Calendar Portlet (Out-of-Box)

Liferay Legend Posts: 2047 Join Date: 10/7/08 Recent Posts
I 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?
Testing Test, modified 4 Years ago.

RE: MVC ResourceCommand Not working for Calendar Portlet (Out-of-Box)

New Member Posts: 5 Join Date: 3/26/12 Recent Posts
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
thumbnail
Andrew Jardine, modified 4 Years ago.

RE: MVC ResourceCommand Not working for Calendar Portlet (Out-of-Box)

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
But "WHAT" are you trying to do? If I understood what Amos said, there are not Resource commands for the Calendar Portlet. You can do ahead and register command classes against the portlet, BUT if none of the views create Resource URLs, you're command class is never going to be hit. Are you basically trying to change the behaviour so that instead of, say, an ActionCommand to do something you instead want to make it more ajax-y with a resource command?
旻 吴, modified 2 Months ago.

RE: MVC ResourceCommand Not working for Calendar Portlet (Out-of-Box)

Junior Member Posts: 56 Join Date: 5/17/17 Recent Posts
Although this is quite an old threa, we have just met the same problem and found out that then answer is "Sorry, you can't".
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.