Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Kiran Jai
Liferay : Why to use Hooks concept for Liferay Login Events ?
April 9, 2012 3:38 AM
Answer

Kiran Jai

Rank: Junior Member

Posts: 38

Join Date: April 9, 2012

Recent Posts

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
Ravi Kumar Gupta
RE: Liferay : Why to use Hooks concept for Liferay Login Events ?
April 9, 2012 3:45 AM
Answer

Ravi Kumar Gupta

Rank: Liferay Legend

Posts: 1182

Join Date: June 23, 2009

Recent Posts

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
RE: Liferay : Why to use Hooks concept for Liferay Login Events ?
April 9, 2012 4:10 AM
Answer

Kiran Jai

Rank: Junior Member

Posts: 38

Join Date: April 9, 2012

Recent Posts

Great point , i didn't thought of this , thank you very much for helping .
David H Nebinger
RE: Liferay : Why to use Hooks concept for Liferay Login Events ?
April 9, 2012 5:29 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7157

Join Date: September 1, 2006

Recent Posts

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
RE: Liferay : Why to use Hooks concept for Liferay Login Events ?
April 26, 2012 6:28 AM
Answer

MICHAIL MOUDATSOS

Rank: Regular Member

Posts: 110

Join Date: October 4, 2011

Recent Posts

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
Brian Scott Schupbach
RE: Liferay : Why to use Hooks concept for Liferay Login Events ?
May 10, 2012 6:25 AM
Answer

Brian Scott Schupbach

Rank: Expert

Posts: 329

Join Date: October 23, 2008

Recent Posts

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
RE: Liferay : Why to use Hooks concept for Liferay Login Events ?
May 10, 2012 11:00 PM
Answer

MICHAIL MOUDATSOS

Rank: Regular Member

Posts: 110

Join Date: October 4, 2011

Recent Posts

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.