Fórum
Hooks in liferay 6
Khanh Vo, modificado 13 Anos atrás.
Hooks in liferay 6
New Member Postagens: 2 Data de Entrada: 24/08/10 Postagens Recentes
In liferay 5.1.0, it looks like we were able to overide classes with the <event> and <event-class>. Liferay 6.0 as removed them so how would I overide the com.liferay.portlet.login.action.LoginAction.java ?
Thanks
Khanh
Thanks
Khanh
Pushpinder Singh, modificado 13 Anos atrás.
RE: Hooks in liferay 6
Junior Member Postagens: 84 Data de Entrada: 21/07/10 Postagens Recentes
Khanh, you can use Ext plugin to override any core functionality. You can even override jsp or properties file.
Gustavo Fernández Gómez, modificado 13 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 191 Data de Entrada: 26/10/07 Postagens Recentes
you have to use:
<!ELEMENT portal-properties (#PCDATA)>
to define the portal properties that the hook overrides
see the dtd
http://www.liferay.com/es/community/wiki/-/wiki/Main/Hook+DTD+-+5.2
<!ELEMENT portal-properties (#PCDATA)>
to define the portal properties that the hook overrides
see the dtd
http://www.liferay.com/es/community/wiki/-/wiki/Main/Hook+DTD+-+5.2
David García González, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 127 Data de Entrada: 14/07/09 Postagens RecentesKhanh Vo:
In liferay 5.1.0, it looks like we were able to overide classes with the <event> and <event-class>. Liferay 6.0 as removed them so how would I overide the com.liferay.portlet.login.action.LoginAction.java ?
Thanks
Khanh
I wanted to override the class ServicePreAction, Wich could be the better option: a hook or an ext plugin?
NOTE: I have created a new class that inherits the original ServicePreAction and then I will override only the method I wanted to implement, in this case, the method servicePre.
Thanks.
Jan Gregor, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 224 Data de Entrada: 20/10/10 Postagens Recentes
Hi,
For this kind of hooks you just need to create a hook wit you portal.properties, so in your liferay-hook.xml will be an entry :
<portal-properties>portal.properties</portal-properties>
You should create this file in your hook into WEB-INF/classes and in this file you can reffer your action events, i.e
servlet.service.events.pre=my.PreEvent
login.events.post=my.PostEvent
Let me know if you have any further questions,
Regards,
Jan.
For this kind of hooks you just need to create a hook wit you portal.properties, so in your liferay-hook.xml will be an entry :
<portal-properties>portal.properties</portal-properties>
You should create this file in your hook into WEB-INF/classes and in this file you can reffer your action events, i.e
servlet.service.events.pre=my.PreEvent
login.events.post=my.PostEvent
Let me know if you have any further questions,
Regards,
Jan.
David García González, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 127 Data de Entrada: 14/07/09 Postagens Recentes
Thanks Jan, I am doing right this way, but tomcat is throwing an exception when it tries to deploy it. This is the files I have created:
liferay-hook.xml
portal.properties
Exception:
The class CustomServicePreAction inherites from the original class com.liferay.portal.events.ServicePreAction.
It is complaining about it does not find the original class.
It is very strange, what could be the problem?
liferay-hook.xml
<hook>
<portal-properties>portal.properties</portal-properties>
</hook>
portal.properties
servlet.service.events.pre=com.intermark.eventmanager.events.CustomServicePreAction
Exception:
Caused by: java.lang.ClassNotFoundException: com.liferay.portal.events.ServicePreAction
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361)
... 27 more
The class CustomServicePreAction inherites from the original class com.liferay.portal.events.ServicePreAction.
It is complaining about it does not find the original class.
It is very strange, what could be the problem?
Anil Sunkari, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Expert Postagens: 427 Data de Entrada: 12/08/09 Postagens Recentes
Hi David,
i think you need to add the parameter like below,hope it will work...
servlet.service.events.pre=com.liferay.portal.events.ServicePreAction,com.intermark.eventmanager.events.CustomServicePreAction
Regards,
Anil Sunkari
i think you need to add the parameter like below,hope it will work...
servlet.service.events.pre=com.liferay.portal.events.ServicePreAction,com.intermark.eventmanager.events.CustomServicePreAction
Regards,
Anil Sunkari
David García González, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 127 Data de Entrada: 14/07/09 Postagens Recentes
Thanks Anil, but it didn't work.
The concatenation makes that these 2 classes are executed in the order the are expecified.
I have to move it to an ext plugin.
The concatenation makes that these 2 classes are executed in the order the are expecified.
I have to move it to an ext plugin.
Jan Gregor, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 224 Data de Entrada: 20/10/10 Postagens Recentes
Hi David,
Dont move it to ext, this is an overhead. Could you please attach the whole log from deployment ?
Regards.
Jan.
Dont move it to ext, this is an overhead. Could you please attach the whole log from deployment ?
Regards.
Jan.
David García González, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 127 Data de Entrada: 14/07/09 Postagens Recentes
I think that the problem is that all the classes that I am implementing in the hook don't find the liferay core classes.
This is another expetion thrown when I deploy the hook. The new class imports the liferay class com/liferay/portal/util/PropsValues
This is another expetion thrown when I deploy the hook. The new class imports the liferay class com/liferay/portal/util/PropsValues
com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for i18n-hook
at com.liferay.portal.kernel.deploy.hot.BaseHotDeployListener.throwHotDeployException(BaseHotDeployListener.java:45)
at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:221)
at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._doFireDeployEvent(HotDeployUtil.java:109)
at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._fireDeployEvent(HotDeployUtil.java:182)
at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:38)
at com.liferay.portal.kernel.servlet.HookContextListener.contextInitialized(HookContextListener.java:36)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1244)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1342)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:303)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NoClassDefFoundError: com/liferay/portal/util/PropsValues
at ServicePreActionUpdated.initImportLARFiles(ServicePreActionUpdated.java:517)
at ServicePreActionUpdated.<init>(ServicePreActionUpdated.java:123)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at com.liferay.portal.deploy.hot.HookHotDeployListener.initEvent(HookHotDeployListener.java:1014)
at com.liferay.portal.deploy.hot.HookHotDeployListener.initEvents(HookHotDeployListener.java:1063)
at com.liferay.portal.deploy.hot.HookHotDeployListener.doInvokeDeploy(HookHotDeployListener.java:464)
at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:218)
... 15 more
Caused by: java.lang.ClassNotFoundException: com.liferay.portal.util.PropsValues
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361)</init>
Jan Gregor, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 224 Data de Entrada: 20/10/10 Postagens Recentes
I think I see the problem,
Can you please post here a list of jar files, which are you using as a dependency ?
I am assuming that you are refferencing classes from portal-impl.jar, is it so ?
Regards,
Jan.
Can you please post here a list of jar files, which are you using as a dependency ?
I am assuming that you are refferencing classes from portal-impl.jar, is it so ?
Regards,
Jan.
David García González, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 127 Data de Entrada: 14/07/09 Postagens Recentes
Thanks Jan, I am using Liferay IDE, and the dependencies I have in the project are shown in the image of the attachment.
I have the dependency portal-impl.jar as a dependency of the liferay-hook-plugin library.
I have the dependency portal-impl.jar as a dependency of the liferay-hook-plugin library.
Anexos:
Jan Gregor, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 224 Data de Entrada: 20/10/10 Postagens Recentes
Hi David,
Remove this dependency. Plugins as portlets/hooks should NEVER use portal-impl as direct dependency. There is Liferay API, which should be used from all plugins and its packaged in portal-service.jar (stored in your AS global lib directory - .i.e in tomcat under /lib/ext). Please add this file as a dependency to your plugin.
The reason for this is, that portal-impl.jar is loaded from another class loader that plugin's libraries and portal-impl.jar includes a lot of singleton classes, which are accesed only by Liferay API itself and never directly by developer.
Regards,
Jan.
Remove this dependency. Plugins as portlets/hooks should NEVER use portal-impl as direct dependency. There is Liferay API, which should be used from all plugins and its packaged in portal-service.jar (stored in your AS global lib directory - .i.e in tomcat under /lib/ext). Please add this file as a dependency to your plugin.
The reason for this is, that portal-impl.jar is loaded from another class loader that plugin's libraries and portal-impl.jar includes a lot of singleton classes, which are accesed only by Liferay API itself and never directly by developer.
Regards,
Jan.
David García González, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 127 Data de Entrada: 14/07/09 Postagens Recentes
But the problem is that my custom class overrides the class ServicePreAction, and this class is in portal-impl.jar
This is my class declaration, If I remove this dependency, the code is not compiling.
This is my class declaration, If I remove this dependency, the code is not compiling.
public class CustomServicePreAction extends ServicePreAction
Jan Gregor, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 224 Data de Entrada: 20/10/10 Postagens Recentes
Please extend the class com.liferay.portal.kernel.events.Action; for your custom post-login-action class, which is included in portal-service.jar
Regards,
Jan.
Regards,
Jan.
David García González, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 127 Data de Entrada: 14/07/09 Postagens RecentesJan Gregor:
Please extend the class com.liferay.portal.kernel.events.Action; for your custom post-login-action class, which is included in portal-service.jar
Thanks, I will try.
My intention was to overwrite only the method and avoid touching the others method of this class
protected void servicePre(HttpServletRequest request,HttpServletResponse response) throws Exception
Jan Gregor, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 224 Data de Entrada: 20/10/10 Postagens Recentes
If you extend the Action class, then the only method you need to implement is public abstract void run(HttpServletRequest request, HttpServletResponse response).
All parameters needed in your class can be retrieved from request object by parsing ThemeDisplay object.
Regards,
Jan.
All parameters needed in your class can be retrieved from request object by parsing ThemeDisplay object.
Regards,
Jan.
David García González, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 127 Data de Entrada: 14/07/09 Postagens Recentes
Thanks Jan, I wanted to take advantage of the code already developed by liferay.
Thank you.
Thank you.
Jan Gregor, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 224 Data de Entrada: 20/10/10 Postagens Recentes
You can not, the class is a Liferay implementation, you need to implement your own class.
Regards,
Jan.
Regards,
Jan.
Fraser Buchanan, modificado 12 Anos atrás.
RE: Hooks in liferay 6
New Member Postagens: 2 Data de Entrada: 14/03/11 Postagens Recentes
Jan,
If you are indeed right then there is definitely an issue with the Liferay documentation of their portal properties which states:
This clearly points developers towards overriding the "ServicePreAction" class. I can confirm that I get exactly the same issue as David.
So this is either a documentation bug or an implementational bug...
If you are indeed right then there is definitely an issue with the Liferay documentation of their portal properties which states:
##
## Default User Public Layouts
##
#
# If the properties "layout.user.public.layouts.enabled" and
# "layout.user.public.layouts.auto.create" are both set to true, then users
# will have public layouts and they will be automatically created. The
# settings below are used for the creation of for the initial public pages.
#
# If you need to add more than one page, set the property
# "default.user.public.layouts.lar" to specifiy a LAR file instead.
#
# For even more complex behavior, override the addDefaultUserPublicLayouts
# method in com.liferay.portal.events.ServicePreAction.
#
This clearly points developers towards overriding the "ServicePreAction" class. I can confirm that I get exactly the same issue as David.
So this is either a documentation bug or an implementational bug...
Jan Gregor, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 224 Data de Entrada: 20/10/10 Postagens Recentes
Hi Fraser,
The documentation is correct, please see full context of the documentation. This class can be overriden only in cases, when you really need to to deep customization. For all "normal" events supported by hook you should directly override the Action class.
Regards,
Jan.
The documentation is correct, please see full context of the documentation. This class can be overriden only in cases, when you really need to to deep customization. For all "normal" events supported by hook you should directly override the Action class.
Regards,
Jan.
Fraser Buchanan, modificado 12 Anos atrás.
RE: Hooks in liferay 6
New Member Postagens: 2 Data de Entrada: 14/03/11 Postagens Recentes
Thanks Jan.
I think in that case the documentation should be more specific as it certainly eludes to something that isn't possible.
Cheers
I think in that case the documentation should be more specific as it certainly eludes to something that isn't possible.
Cheers
Rick Dangerous, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Junior Member Postagens: 61 Data de Entrada: 25/01/11 Postagens RecentesJan Gregor:
Hi David,
Remove this dependency. Plugins as portlets/hooks should NEVER use portal-impl as direct dependency. There is Liferay API, which should be used from all plugins and its packaged in portal-service.jar (stored in your AS global lib directory - .i.e in tomcat under /lib/ext). Please add this file as a dependency to your plugin.
The reason for this is, that portal-impl.jar is loaded from another class loader that plugin's libraries and portal-impl.jar includes a lot of singleton classes, which are accesed only by Liferay API itself and never directly by developer.
Regards,
Jan.
I have similar problem:
- Defined some listeners with a hook. One of them defined when a Group is Created.
public class GroupListener extends BaseModelListener<group> {
}
</group>
- Defined OnAfterCreate event, when fired I need to assign template to a Community (Group) :
CommunitiesUtil.applyLayoutSetPrototypes(model, 0L, 1111111);
Liferay reports:
Caused by: java.lang.NoClassDefFoundError: com/liferay/portlet/communities/util/CommunitiesUtil
- Then I put /docroot/META-INF/context.xml... without success, same Exception :
<context>
<loader loaderClass="com.liferay.support.tomcat.loader.PortalClassLoader" />
</context>
- Liferay IDE plugin put at my Build Path, (automatically when I Importing from SDK) the LIFERAY HOOK PLUGIN API Library, with portal-impl.jar inside...in all my hooks that was imported by Liferay IDE. ¿?
How can I access to Liferay API from a Hook, to use com.liferay.portlet.communities.util.CommunitiesUtil with success ¿?¿?
Thanks
David García González, modificado 12 Anos atrás.
RE: Hooks in liferay 6
Regular Member Postagens: 127 Data de Entrada: 14/07/09 Postagens RecentesRick Dangerous:
- Liferay IDE plugin put at my Build Path, (automatically when I Importing from SDK) the LIFERAY HOOK PLUGIN API Library, with portal-impl.jar inside...in all my hooks that was imported by Liferay IDE. ¿?
I have the same problem, Liferay IDE puts this jar inside. Is it ok or do we have to remove it manually?
Rick, perhaps the class com.liferay.portlet.communities.util.CommunitiesUtil is not in the public Liferay API and it is not recommended to use it.
Oluwasegun Diyan, modificado 11 Anos atrás.
RE: Hooks in liferay 6
New Member Postagens: 4 Data de Entrada: 07/08/12 Postagens Recentes
Hello David,
I'm believing you've resolved this issue by now.
I'm also trying to override the LoginAction class but the portal-impl.jar restrictions just killing it (you obviously know this).
Please can you give me a detailed approach (possibly with code and config snippets) as to how to achieve this?
I really would appreciate this.
Thanks.
I'm believing you've resolved this issue by now.
I'm also trying to override the LoginAction class but the portal-impl.jar restrictions just killing it (you obviously know this).
Please can you give me a detailed approach (possibly with code and config snippets) as to how to achieve this?
I really would appreciate this.
Thanks.
Oluwasegun Diyan, modificado 11 Anos atrás.
RE: Hooks in liferay 6
New Member Postagens: 4 Data de Entrada: 07/08/12 Postagens Recentes
Hello,
Don't bother anymore.
I got it resolved already.
Thanks anyway.
Don't bother anymore.
I got it resolved already.
Thanks anyway.