Foren

Liferay : Why to use Hooks concept for Liferay Login Events ?

Kiran Jai, geändert vor 12 Jahren.

Liferay : Why to use Hooks concept for Liferay Login Events ?

Junior Member Beiträge: 38 Beitrittsdatum: 09.04.12 Neueste Beiträge
Hi ,

I have gone through Liferay Hooks tutorial it specifies that , the basic functionality of Liferay can be chnaged using Hooks
And i have come across a example where the author is using Liferay Hooks for overriding the default |Liferay Login pre and post events using hooks .

But i have a question here can't we do this way , that is by specfying it inside the portal-ext.properties file as shown

portal-ext.properties

login.events.post=com.MyLoginPostAction
logout.events.pre=com.MyLoginPreAction


And i seem that this way it is easier to do thinns where as if we sue the Hooks concept , we need to mention inside the liferay-hooks.xml file


<portal-properties>portal.properties</portal-properties>


Next, create the file portal.properties inside example-hook/docroot/WEB-INF/src with the following content:

login.events.pre=com.sample.hook.LoginAction




Please specify what approach is best
thumbnail
Ravi Kumar Gupta, geändert vor 12 Jahren.

RE: Liferay : Why to use Hooks concept for Liferay Login Events ?

Liferay Legend Beiträge: 1302 Beitrittsdatum: 24.06.09 Neueste Beiträge
Think about just one point.. if you need to remove that hook in production.. modifying portal-ext.properties will need server restart while hook will just need to be deleted from webapps.. emoticon

There can be more points.. but the line which says hooks can be hot-deployed teaches all..
Kiran Jai, geändert vor 12 Jahren.

RE: Liferay : Why to use Hooks concept for Liferay Login Events ?

Junior Member Beiträge: 38 Beitrittsdatum: 09.04.12 Neueste Beiträge
Great point , i didn't thought of this , thank you very much for helping .
thumbnail
David H Nebinger, geändert vor 12 Jahren.

RE: Liferay : Why to use Hooks concept for Liferay Login Events ?

Liferay Legend Beiträge: 14916 Beitrittsdatum: 02.09.06 Neueste Beiträge
Kiran Jai:
Great point , i didn't thought of this , thank you very much for helping .


Yeah, you're new here. Stick around for awhile and you'll eventually understand why things were done how they were done, and most of the time there's a pretty good reason behind it...

I think everyone first coming to Liferay asks why certain pieces appear harder than they need to be, but eventually when the whole picture comes into focus it gets easier to understand why things are the way they are...
MICHAIL MOUDATSOS, geändert vor 11 Jahren.

RE: Liferay : Why to use Hooks concept for Liferay Login Events ?

Regular Member Beiträge: 110 Beitrittsdatum: 04.10.11 Neueste Beiträge
I think you guys are right about removing a hook but how about adding a hook, which adds a definition of e.g. logout.events.post
I lost some time figuring out what was going wrong until I thought "Well the portal.properties are being overridden, so maybe a server restart is needed after all..." and yes(!) when I restarted the app server the property took effect. Most annoyingly, when I decided to change my class as to run as a logout.events.pre rather than as a logout.events.post (because I wanted the id of the session while it was valid, anyway) not even the restart of the server resulted in my changes taking effect! I stripped the property, I restarted, I added the new property, I restarted and then it worked.

For the benefit of your doubt I will also add that
- I already had another hook overriding some events (nevertheless, this must have no effect)
-(Most importantly) In my hook I also defined a service.xml (I needed some extra Entities for the goal of my hook) which I set to use the same namespace as the service.xml of a portlet I had already deployed. As a consequence I was getting some HotDeployException (*) every time I deployed the hook, however the code changes (Attention! The CODE changes not the property definition changes) would take effect at every deployment.

Unless the latter is the cause of the new, overridden in hook, properties not taking effect, then new properties in a hook need a restart...
And even if the latter is the case of my hot deployment not working properly, why the change from logout.events.post to logout.events.pre did not take effect after a single restart?

any ideas?

Thank you in advance

(*)Error stack trace included somewhere: "Build namespace xx has build number xxx which is newer than x"; deployment ended with: "Registering hook for xxx-hook" and "xxx-hook is available for use" as usual
thumbnail
Brian Scott Schupbach, geändert vor 11 Jahren.

RE: Liferay : Why to use Hooks concept for Liferay Login Events ?

Expert Beiträge: 329 Beitrittsdatum: 23.10.08 Neueste Beiträge
It's hard to tell without seeing the full stack trace but either your hook was built under a different liferay version or your java version doesn't match what you have in production.
MICHAIL MOUDATSOS, geändert vor 11 Jahren.

RE: Liferay : Why to use Hooks concept for Liferay Login Events ?

Regular Member Beiträge: 110 Beitrittsdatum: 04.10.11 Neueste Beiträge
We do not need the stack trace. I also tried with another hook that produces no errors and still I needs a reboot when I override a portal.properties property, for the addition to take effect.