Foren

Hooks in liferay 6

Khanh Vo, geändert vor 13 Jahren.

Hooks in liferay 6

New Member Beiträge: 2 Beitrittsdatum: 24.08.10 Neueste Beiträge
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
Pushpinder Singh, geändert vor 13 Jahren.

RE: Hooks in liferay 6

Junior Member Beiträge: 84 Beitrittsdatum: 21.07.10 Neueste Beiträge
Khanh, you can use Ext plugin to override any core functionality. You can even override jsp or properties file.
thumbnail
Gustavo Fernández Gómez, geändert vor 13 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 191 Beitrittsdatum: 26.10.07 Neueste Beiträge
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
thumbnail
David García González, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 127 Beitrittsdatum: 14.07.09 Neueste Beiträge
Khanh 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.
thumbnail
Jan Gregor, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 224 Beitrittsdatum: 20.10.10 Neueste Beiträge
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.
thumbnail
David García González, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 127 Beitrittsdatum: 14.07.09 Neueste Beiträge
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
<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?
thumbnail
Anil Sunkari, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Expert Beiträge: 427 Beitrittsdatum: 12.08.09 Neueste Beiträge
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
thumbnail
David García González, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 127 Beitrittsdatum: 14.07.09 Neueste Beiträge
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.
thumbnail
Jan Gregor, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 224 Beitrittsdatum: 20.10.10 Neueste Beiträge
Hi David,

Dont move it to ext, this is an overhead. Could you please attach the whole log from deployment ?

Regards.
Jan.
thumbnail
David García González, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 127 Beitrittsdatum: 14.07.09 Neueste Beiträge
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

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>
thumbnail
Jan Gregor, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 224 Beitrittsdatum: 20.10.10 Neueste Beiträge
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.
thumbnail
David García González, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 127 Beitrittsdatum: 14.07.09 Neueste Beiträge
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.
thumbnail
Jan Gregor, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 224 Beitrittsdatum: 20.10.10 Neueste Beiträge
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.
thumbnail
David García González, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 127 Beitrittsdatum: 14.07.09 Neueste Beiträge
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.

public class CustomServicePreAction extends ServicePreAction
thumbnail
Jan Gregor, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 224 Beitrittsdatum: 20.10.10 Neueste Beiträge
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.
thumbnail
David García González, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 127 Beitrittsdatum: 14.07.09 Neueste Beiträge
Jan 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
thumbnail
Jan Gregor, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 224 Beitrittsdatum: 20.10.10 Neueste Beiträge
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.
thumbnail
David García González, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 127 Beitrittsdatum: 14.07.09 Neueste Beiträge
Thanks Jan, I wanted to take advantage of the code already developed by liferay.

Thank you.
thumbnail
Jan Gregor, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 224 Beitrittsdatum: 20.10.10 Neueste Beiträge
You can not, the class is a Liferay implementation, you need to implement your own class.

Regards,
Jan.
Fraser Buchanan, geändert vor 12 Jahren.

RE: Hooks in liferay 6

New Member Beiträge: 2 Beitrittsdatum: 14.03.11 Neueste Beiträge
Jan,
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...
thumbnail
Jan Gregor, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 224 Beitrittsdatum: 20.10.10 Neueste Beiträge
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.
Fraser Buchanan, geändert vor 12 Jahren.

RE: Hooks in liferay 6

New Member Beiträge: 2 Beitrittsdatum: 14.03.11 Neueste Beiträge
Thanks Jan.

I think in that case the documentation should be more specific as it certainly eludes to something that isn't possible.

Cheers
Rick Dangerous, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Junior Member Beiträge: 61 Beitrittsdatum: 25.01.11 Neueste Beiträge
Jan 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
thumbnail
David García González, geändert vor 12 Jahren.

RE: Hooks in liferay 6

Regular Member Beiträge: 127 Beitrittsdatum: 14.07.09 Neueste Beiträge
Rick 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, geändert vor 11 Jahren.

RE: Hooks in liferay 6

New Member Beiträge: 4 Beitrittsdatum: 07.08.12 Neueste Beiträge
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.
Oluwasegun Diyan, geändert vor 11 Jahren.

RE: Hooks in liferay 6

New Member Beiträge: 4 Beitrittsdatum: 07.08.12 Neueste Beiträge
Hello,

Don't bother anymore.

I got it resolved already.

Thanks anyway.