Foros de discusión
How can I add the custom MVC ResourceCommand in Out-of-Box portlet
How can I add the custom MVC ResourceCommand in Out-of-Box portlet
Junior Member Mensajes: 33 Fecha de incorporación: 1/02/12 Mensajes recientesIn Liferay DXP, How can I add the custom MVCResourceCommand in Out-of-Box portlet (Ex. Search Portlet)?
RE: How can I add the custom MVC ResourceCommand in Out-of-Box portlet
Liferay Legend Mensajes: 14914 Fecha de incorporación: 2/09/06 Mensajes recientesRE: How can I add the custom MVC ResourceCommand in Out-of-Box portlet
Junior Member Mensajes: 33 Fecha de incorporación: 1/02/12 Mensajes recientesAs per given link, it's overriding the MVCResourceCommand which already exist in the system. But my original question is that Portlet does not exist the any of ResourceCommand classes that time I have to add my own class and do my functionality.
For Example, there is out of box SearchPortlet, it doest not exists any XXXResourceCommand classes. AJAX control code is written in serveResource method of the Search MVC Portlet (SearchPortlet - MVCPortlet). So I have to add my extra code when my custom ajax call comes.
I think two alternative way for this customizing:
1. I can add new custom XXXResourceCommand classes for handling my custom AJAX control.
2. I can modify the serveResource method MVCPortlet. - (No idea how can I modify this code in DXP)
So how can I do this? I try first way but not configure properly may be.
This below is my code which I follow 1st way.
view.jsp
I add the code fragment in jsp file
<portlet:resourceurl var="searchResourceURL" id="searchResource">
<liferay-portlet:param name="cmd" value="seachContent" />
</portlet:resourceurl>
<aui:script>
AUI().use('aui-base','aui-io-request',function (A) {
var myAjaxRequest=A.io.request('<%=searchResourceURL%>',{
dataType: 'json',
sync:true,
method:'POST',
data:{
<portlet:namespace />searchKey:inputValue,
},
autoLoad:false,
on: {
success:function(){
var data=this.get('responseData');
console.log(data);
alert(data);
}}
});
myAjaxRequest.start();
});
</aui:script>
SearchResourceCommand.java
package com.vks.liferay.search; // this my custom package
// Assume all imports available here
@Component(immediate = true, property = { "javax.portlet.name=com_liferay_portal_search_web_portlet_SearchPortlet",
"mvc.command.name=searchResource", "service.ranking:Integer=100" }, service = MVCResourceCommand.class)
public class SearchResourceCommand 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;
@Reference(target = "(&(osgi.web.symbolicname=com.liferay.portal.search.web) (javax.portlet.name=com_liferay_portal_search_web_portlet_SearchPortlet))")
public void setMvcResourceCommand(MVCResourceCommand mvcResourceCommand) {
this.mvcResourceCommand = mvcResourceCommand;
}
public MVCResourceCommand getMvcResourceCommand() {
return this.mvcResourceCommand;
}
@Reference(target = "(osgi.web.symbolicname=com.liferay.portal.search.web)")
protected ServletContext servletContext;
}
bnd.bnd
Bundle-Name: search-jsp-hook
Bundle-SymbolicName: com.vks.liferay.search
Bundle-Version: 1.0.0
Fragment-Host: com.liferay.portal.search.web;bundle-version="1.1.2"
-sources: true
Web-ContextPath:/search-jsp-hook
This whole code I post here. I try for this but it's not binding with SearchPortlet.
Is it wrong anything in SearchResourceCommand.java file because it's not binding with the SearchPortlet.
RE: How can I add the custom MVC ResourceCommand in Out-of-Box portlet
Liferay Legend Mensajes: 14914 Fecha de incorporación: 2/09/06 Mensajes recientesFor your resource command implementation, you just need to assign it to the search portlet's name. The Liferay MVC framework will wire it all together and the search portlet will act like it has always had the resource command.
RE: How can I add the custom MVC ResourceCommand in Out-of-Box portlet
New Member Mensajes: 7 Fecha de incorporación: 31/07/17 Mensajes recientesRegards, Gena
RE: How can I add the custom MVC ResourceCommand in Out-of-Box portlet
New Member Mensajes: 7 Fecha de incorporación: 31/07/17 Mensajes recientesRE: How can I add the custom MVC ResourceCommand in Out-of-Box portlet
Liferay Legend Mensajes: 14914 Fecha de incorporación: 2/09/06 Mensajes recientesIf you create a bundle with a unique ResourceMVCCommand that has it's own mvc.command.name but is wired up to an existing MVCPortlet implementation, this is not handled any differently from OSGi than if the class was contained in the original bundle.
That said, if I create an MVCPortlet extension and override how the command handlers are found, I could prevent additional commands from being added.
I think one issue the OP had was combining the ResourceMVCCommand class into the JSP fragment bundle; this is a no-no because fragment bundles are not executable, they don't become active, they just replace files from the original bundle. Therefore they cannot really add new components directly. Any new or overriding ResourceMVCCommand classes would need to be separated out to their own bundle.
RE: How can I add the custom MVC ResourceCommand in Out-of-Box portlet
New Member Mensajes: 7 Fecha de incorporación: 31/07/17 Mensajes recientesIf you create a bundle with a unique ResourceMVCCommand that has it's own mvc.command.name but is wired up to an existing MVCPortlet implementation, this is not handled any differently from OSGi than if the class was contained in the original bundle.
This was also my expectation...
I think one issue the OP had was combining the ResourceMVCCommand class into the JSP fragment bundle; this is a no-no because fragment bundles are not executable, they don't become active, they just replace files from the original bundle. Therefore they cannot really add new components directly. Any new or overriding ResourceMVCCommand classes would need to be separated out to their own bundle.
I've splitted the fragment into two bundles, just like you suggested. The bundle with the new MVCResourceCommand also may not be a fragment
(i removed a fragment host entry) to work.
Many thanks, even it took me about two days of work...
Regards Gena
RE: How can I add the custom MVC ResourceCommand in Out-of-Box portlet
New Member Mensajes: 5 Fecha de incorporación: 1/10/10 Mensajes recientesHi Gena,
I'm facing the same issue on the Calendar portlet: I tried to follow the LR guidelines and this thread, but neither can I add a new resource (I get calendar-does-not-serve-unknown-resource-x) nor can I override the 'calendarResources' resource id. Would you pls share your implementation ?
Thank you very much
Francesco
RE: How can I add the custom MVC ResourceCommand in Out-of-Box portlet
New Member Mensajes: 7 Fecha de incorporación: 31/07/17 Mensajes recientesHello Francesco,
in my case i wanted to add custom ResourceCommand to an existing portlet. The extention to the existing portlet were done via the fragment. I've modified a JSP fragment and inserted the call to
<liferay-portlet:resourceURL id="searchContent" var="searchResourceURL" copyCurrentRenderParameters="false"/>
The resource searchContent is served via newly created MVCResourceCommand named searchContent:
@Component(immediate = true, property = {"javax.portlet.name=" + SearchPortletKeys.SEARCH, "mvc.command.name=searchContent", "service.ranking:Integer=100000"}, service = MVCResourceCommand.class) public class AutoCompleteSearchCommand implements MVCResourceCommand {
but i should create a completeley new bundle for AutoCompleteSearchCommand to be recognized by osgi.
It couldn't be done just by adding the AutoCompleteSearchCommand to the fragment because fragment accepts only modifications on existing artefacts within the Fragment-Host and the new command didn't exist. I hope, the information helps.
Kind regards, Gena
RE: How can I add the custom MVC ResourceCommand in Out-of-Box portlet
New Member Mensajes: 5 Fecha de incorporación: 26/03/12 Mensajes recientesGhenadii Batalski:Hello Francesco,
in my case i wanted to add custom ResourceCommand to an existing portlet. The extention to the existing portlet were done via the fragment. I've modified a JSP fragment and inserted the call to
<liferay-portlet:resourceURL id="searchContent" var="searchResourceURL" copyCurrentRenderParameters="false"/>The resource searchContent is served via newly created MVCResourceCommand named searchContent:
@Component(immediate = true, property = {"javax.portlet.name=" + SearchPortletKeys.SEARCH, "mvc.command.name=searchContent", "service.ranking:Integer=100000"}, service = MVCResourceCommand.class) public class AutoCompleteSearchCommand implements MVCResourceCommand {but i should create a completeley new bundle for AutoCompleteSearchCommand to be recognized by osgi.
It couldn't be done just by adding the AutoCompleteSearchCommand to the fragment because fragment accepts only modifications on existing artefacts within the Fragment-Host and the new command didn't exist. I hope, the information helps.
Kind regards, Gena
Hi I'm trying to implement MVCResourceCommand for calendar
portlet but its not working
@Component( immediate = true, property = {"javax.portlet.name=com_liferay_calendar_web_portlet_CalendarPortlet", "mvc.command.name=calendarRenderingRules" }, 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; }
RE: How can I add the custom MVC ResourceCommand in Out-of-Box portlet
New Member Mensajes: 7 Fecha de incorporación: 31/07/17 Mensajes recientesHello, does your ResourceCommad called at all? If not, what is your patching approach? You should create for your additional command a new osgi bundle. If you try to add new command to a fragment, it won't work.
Regards, Gena
RE: How can I add the custom MVC ResourceCommand in Out-of-Box portlet
Liferay Legend Mensajes: 14914 Fecha de incorporación: 2/09/06 Mensajes recientesThis code has issues.
First, if you are trying to override an existing MVCResourceCommand (that's not completely clear), it's missing a service ranking override.
Second, the mvcResourceCommand member is never initialized, so it is null. Even if the code did get called, you'd end up with an NPE as a result.
RE: How can I add the custom MVC ResourceCommand in Out-of-Box portlet
New Member Mensajes: 2 Fecha de incorporación: 24/10/19 Mensajes recientesHi,
In Liferay DXP, How can I add the custom MVCResourceCommand in Out-of-Box portlet (Ex. Search Portlet)?
RE: How can I add the custom MVC ResourceCommand in Out-of-Box portlet
Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes- Create a new module (or use an existing one if you want)
- Create your new MVCResourceCommand class
- In the @Component annotation, make sure you specify the javax.portlet.name= the portletId for the Search Portlet -- or whatever portlet you want to associate the resource command with
That's it. I've used this trick many times. The only thing you need to make sure, which of course has always been the case -- including pre-7.x, is that you specify the correct portletId and a layoutId that has the portlet. If you have embedded the search portlet in your theme, then you can basically hit the resource command from any page where you theme is applied.