« Back

Liferay Hook Plugin Support | Netbeans Portal Pack 3.0.2

General Blogs March 22, 2009 By Santh Chetan Chadalavada

 

Portal Pack makes life easier yet again !!. This time with the NetBeans Hook Plugin for Liferay.

Available @ Netbeans PortalPack 3.0.2


Introduction: This plugin has been developed to provide hook tooling support through Netbeans Portal Pack. For more information

on Liferay Hook checkout the Portal Hook Plugins Wiki

This new feature will help creating different kinds of hooks supported by Liferay Portal. Lets look each type of hook and how we can create them using Netbeans Portal Pack plugin.

  • Event Type Hook :  Liferay provides different kind of event type hooks and Portal Pack now supports all the different kinds of event hooks. For example, add a post login hook to do your custom stuff after each user login.
  1. Create a web project:
  2. In Server and Settings choose Liferay Portal Server 5.2.2 and click on Finish the create the project.
  3. Right click on the project. In Categories Select WebSpace/Liferay Plugins -> Hook Plugin. 
  4. Click On Next. From the Hooks Wizard top dropdown choose Event Handler Hook.
  5. Provide ClassName and Package. Choose the Event Type from the bottom drop down and click Finish. 
  6. liferay-hook.xml, portal.properties, Event class files will be generated with the provided information.You can edit the java file put some code and save.
  7. Right click on the project and select Deploy.
  • Model Listener Hook : Using this hooks, you can do specific tasks whenever there is any CRUD operation in a specific model.
  1. Right click on the project-> Select Hook Plugin -> Choose Model Listeners Hook. 
  2. Choose the model by Clicking on Search. 
  3. Click Finish. Modify the code generated by Portal Pack Plugin, save it, Right click on the project and deploy. 
  • Jsp Hook : Using this hook, user can customize the core portal jsps/portlet in a decoupled manner without touching the core. For example, you can change the look and feel of the blog portlet in your hook application. And once you undeploy the hook application, the customization will go away. The Portal Pack provides wizard to create jsp hooks where user can select the core portal components which he/she wants to customize and the required files will be automatically imported to the hooks application. This feature can be used by SI for the portal customization.
  1. From the Hook Plugin Wizard choose the Jsp Hook from the drop down. Liferay Core jsp root folder(html) will be populated in the left pane. 
  2.  
  3. Once clicked on Finish, folder structure will be created under the default custom jsp directory "/WEB-INF/jsp".
  • Portal.properties Hook : You can override certain portal.properties through your hooks application.
  1. Select the Properties Hook from the drop down on a Clean Web Project(Which does not have a hook created to it).
  2. portal.properties will be create with commented pre entires supported to be overriden.

 

Undeploying Hooks:

All the deployed hook plugins can be undeployed from Netbeans -> Services -> Liferay Server -> Global -> Hooks.

Right Click on the Hook Plugin and selecting Undeploy will undeploy it from the Portal Server. 

 

Threaded Replies Author Date
Very nice Santh, Keep up the good work! Jorge Ferrer March 23, 2009 11:56 AM
This is very good stuff Chetan! Manish Dixit March 25, 2009 5:02 PM
I have just tried to use the JSP hook facility,... Peter B West April 13, 2009 6:23 PM
Peter, I guess you are using "Directory... Santh Chetan Chadalavada April 13, 2009 11:07 PM
Chetan, That worked like a charm. Many thanks.... Peter B West April 14, 2009 6:16 AM
Chetan, I now have a related problem, based on... Peter B West April 15, 2009 7:45 PM
It seems to work if I simply explode the... Peter B West April 15, 2009 9:02 PM
Curiously, this seems to work on mu local... Peter B West April 15, 2009 9:23 PM
Peter, if I understand correctly ur query, you... Santh Chetan Chadalavada April 15, 2009 10:24 PM
Thanks Chetan. That works, and I see in the... Peter B West April 15, 2009 10:53 PM
>>However, the jsp is not being activated. It... satya ranjan April 15, 2009 11:25 PM
Hmm. It's not there. On my local system, I do... Peter B West April 15, 2009 11:41 PM
Peter, you said you exploded the war previously... Santh Chetan Chadalavada April 16, 2009 12:43 AM
I'll see if I can get the server restarted... Peter B West April 16, 2009 1:31 AM
I removed JSP-hook from webapps, restarted the... Peter B West April 16, 2009 4:35 AM
Whats the server version(OS + liferay version)?... Santh Chetan Chadalavada April 16, 2009 5:07 AM
I created a new hook application and tested it... Peter B West April 17, 2009 1:33 AM
I'm running 5.2.2 on OpenSuSE locally. The... Peter B West April 17, 2009 2:11 AM
I want to create a auto-login hook. Is that... Tony Lim April 18, 2009 10:39 AM
It is very much possible. Portal Pack provides... Santh Chetan Chadalavada April 21, 2009 6:56 AM
Will the portal pack be updated to work with... Marcelo Ruiz Camauër August 3, 2010 2:57 PM
Hi Marcelo, You should probably ask Oracle... Jorge Ferrer August 4, 2010 1:17 AM
I cannot create a Jsp Hook with the 3.0.2... Thomas Kellerer July 14, 2009 3:08 AM
Hi Thomas, Hooks works fine with the 3.0.2... Santh Chetan Chadalavada July 14, 2009 11:16 AM
Hi, I wanted to create a ModelListener, that... Dennis Nes September 30, 2009 5:52 AM
Hi Dennis, which version of liferay and... Santh Chetan Chadalavada September 30, 2009 7:18 AM
Anyone here who can send me the Plugins please... Darko Joseph Hojnik November 4, 2009 8:04 PM
^^ ups webmaster {a} virtualizing.org ;) Darko Joseph Hojnik November 4, 2009 8:04 PM
http://blogs.sun.com/lukas/entry/page_not_found... Santh Chetan Chadalavada November 4, 2009 9:41 PM
hi Chetan let me thanks for ur good work now... vishal jha June 8, 2010 5:03 AM
Hello, thank you for the post. Just came across... Mario Rosemario December 22, 2010 5:19 AM
[...] Liferay Hook Plugin Support , Netbeans... Anonymous September 4, 2014 1:33 AM

Very nice Santh,

Keep up the good work!
Posted on 3/23/09 11:56 AM.
This is very good stuff Chetan!
Posted on 3/25/09 5:02 PM.
I have just tried to use the JSP hook facility, and nothing much happened. Has anyone else tried this?

My instance is 5.2.2 in Tomcat 5.5. I created web projects using both the default JEE5 and JEE4, although I didn't change the source level from 1.6.

I created a JSP for portal/login, modified the open_id.jsp to include a legend in the fieldset, and deployed. The following output was in NB

23:35:32,052 INFO [AutoDeployDir:183] Processing LifeRayTest-hook.xml
23:35:32,053 INFO [PortletAutoDeployListener:67] Deploying package as a web application
23:35:32,053 INFO [PortletAutoDeployListener:77] Copying portlets for /opt/nb/liferay/liferay-portal-tomcat-5.5-5.2.2/deploy/LifeRayTest-hook.xml
23:35­:32,054 INFO [PortletAutoDeployListener:87] Portlets for /opt/nb/liferay/liferay-portal-tomcat-5.5-5.2.2/deploy/LifeRayTest-hook.xml copied successfully. Deployment will start in a few seconds.
/home/pbw/NetBeansProjects/LifeRayTest-hook/build/web updated successfully.
Time taken for massaging : 22sec.
PortalPack Message : Deployed Successfully.

When I try to access the JSP (by attempting to login with OpenID) my changes are not visible. Searching the tomcat tree for files named open_id.* yields two versions, including the original of the one I modified.

The file that gets deployed is LifeRayTest-hook.xml (my project name is LifeRayTest-hook). It's contents are:
<Context docBase="/home/pbw/NetBeansProjects/LifeRayTest-hook/build/web">
</Context>

What am I doing wrong?
Posted on 4/13/09 6:23 PM.
Peter,

I guess you are using "Directory Deployment Enabled" on the server properties. Hooks type application does not work with Directory Deployment as it has to go through proper war deployment. So workaround is to

1. Goto Server config panel.
2. Uncheck and disable "Directory Deployment Enabled" and click on Apply.
3. Undeploy the application and then redeploy again.

This case was taken care in Glassfish bundle where it does regular deployment for hook application even if Directory Deployment is selected. So we have to handle the same case for tomcat too.

Thanks for bringing this up. Please let us know if you are still facing the issue.

Chetan
Posted on 4/13/09 11:07 PM in reply to Peter B West.
Chetan,

That worked like a charm. Many thanks. I'll let you know if anything else crops up.

Peter
Posted on 4/14/09 6:16 AM in reply to Santh Chetan Chadalavada.
Chetan,

I now have a related problem, based on my ignorance of Tomcat. I have been deploying my JSP hook from NetbBeans - it's as simple as making sure mysql and the liferay server are running, then invoking Deploy on the menu of the project I have created.

Now I need to deploy on a remote server. I construct the .war file, but what do I have to do to get it recognised and acted upon?

The deployment from my NetBeans project seem to invoke a NetBeans internally defined target called nbjpdaappreloaded.


Peter
Posted on 4/15/09 7:45 PM in reply to Santh Chetan Chadalavada.
It seems to work if I simply explode the JSP-hook.war into tomcat.../webapps/JSP-hook.

Is this all I need to do?

Peter
Posted on 4/15/09 9:02 PM in reply to Peter B West.
Curiously, this seems to work on mu local system, but no on the server. Are there properties which must be set to enable hooks?

Peter
Posted on 4/15/09 9:23 PM in reply to Peter B West.
Peter, if I understand correctly ur query, you want to deploy the JSP-hook.war in a remote server rt?

You can just upload the war file to your server's autodeploy location. for ex: liferay-portal-5.2.2\deploy. You don't need to explicitly explode it into webapps dir.

I don't think you need to make any changes to war unless the portal versions are way too different AFAIK.
Posted on 4/15/09 10:24 PM in reply to Peter B West.
Thanks Chetan. That works, and I see in the log that the:

Hook for JSP-hook is available for use

However, the jsp is not being activated. It is possible that the login.jsp has been overridden be something else on the server. I don't know how to check this readily.

One other interesting point: I cannot see the hook in the Control Panel Plugins Installation page, either on my local system, where it works, or on the server, where it does not.

Peter
Posted on 4/15/09 10:53 PM in reply to Santh Chetan Chadalavada.
>>However, the jsp is not being activated. It is possible that the login.jsp has been overridden be something else on the server. I don't know how to check this readily.

You can go to the following location and check the content of login.jsp to see your hook login.jsp content are there or not.

$liferay-portal-5.2.2\tomcat-5.5.27\webapps\ROOT\html\portlet\login

During jsp hook deployment, the liferay server basically copies the jsps in your hook application to the core portal deployed location and takes backup of orignal jsps. So whenever you undeploy your hook application, the original jsps get back to their original location.
Posted on 4/15/09 11:25 PM in reply to Peter B West.
Hmm. It's not there. On my local system, I do have login.jsp and login.portal.jsp. etc.

Peter
Posted on 4/15/09 11:41 PM in reply to satya ranjan.
Peter, you said you exploded the war previously in the webapps dir. That could have messed up something, not sure.
Try undeploying/remove the jsp-hook folder the webapp, restart the server and redeploy again by copying the hook war in deploy location and see if it comes up.

Chetan
Posted on 4/16/09 12:43 AM in reply to Peter B West.
I'll see if I can get the server restarted later this evening.

Peter
Posted on 4/16/09 1:31 AM in reply to Santh Chetan Chadalavada.
I removed JSP-hook from webapps, restarted the server, dropped the war file in deploy, saw the appropriate message about the hook being available, and the situation is the same. The contents of ROOT/html/portlets/login is unchanged.

Any other suggestions?
Posted on 4/16/09 4:35 AM in reply to Peter B West.
Whats the server version(OS + liferay version)? Does you hook application have any portlet? Is the same hook app working on local machine?

If its not a big task, could you create a new hook application and copy all those changes you have to make and then use Netbeans "build" to build the war get the war and deploy it in server.
Posted on 4/16/09 5:07 AM in reply to Peter B West.
I created a new hook application and tested it locally. It works. I then tried deploying it on the remote server. Again it didn't work.
Posted on 4/17/09 1:33 AM in reply to Santh Chetan Chadalavada.
I'm running 5.2.2 on OpenSuSE locally. The remote system is
SUSE Linux Enterprise Server 10 (i586)
VERSION = 10
PATCHLEVEL = 2

I think the LifeRay version is 5.2.1.
Posted on 4/17/09 2:11 AM in reply to Peter B West.
I want to create a auto-login hook. Is that possible using portal pack and net beans? Similar to the one here:

http://wikis.sun.com/display/websynergy/AutoLogin+Hook+for+OpenSSO+Agent?fo­cusedCommentId=92143831

Except I'll be using a different SSO.
Posted on 4/18/09 10:39 AM in reply to Peter B West.
It is very much possible. Portal Pack provides you the basic infrastructure for your hook plugin.
Posted on 4/21/09 6:56 AM in reply to Tony Lim.
I cannot create a Jsp Hook with the 3.0.2 plugin and NB 6.7

When I select a "normal" Tomcat as the runtime, I do get the dialog where I can select the hook type, but after selecting the JspHook I'm presented with a selection from my userhome(?) and the error message that this can only be used when the runtime is a Liferay Portal server.

So I created a Liferay Portal Server in the Servers tab pointing to my Tomcat directory. When I now select "New -> Other -> PortalHook" I get a very simply dialog that asks for the location of a .java file. I cannot select any Hook type.

What am I missing?
Posted on 7/14/09 3:08 AM.
Hi Thomas, Hooks works fine with the 3.0.2 plugin and NB 6.7. You can use Hooks plugin only with Liferay Portal Server/ Wespace Server runtime i.e you need to add Liferay Portal Server which is pointing to a valid Liferay Home directory.

Once you do that. Create a new Web Project -> Right click on the project -> Other ->
WebSpace/Liferay Plugins -> Hook Plugin and then you should be able to see the hook wizard screen.

If anything goes wrong with the steps above then please check your Liferay installation.

Let us know if the issue is solved.
Posted on 7/14/09 11:16 AM in reply to Thomas Kellerer.
Hi, I wanted to create a ModelListener, that fires, when there is a new order in the shop. So the code looks like this:
public void onAfterCreate(Object arg0) throws ModelListenerException {

com.liferay.portlet.shopping.model.ShoppingOrder mdlObj
= (com.liferay.portlet.shopping.model.ShoppingOrder) arg0;

}

But it returns error after the address input portlet:
java.lang.UnsupportedOperationException: Not supported yet.
at com.test.NewHookAction.onBeforeUpdate(NewHookAction.java:76)

Did I do anything wrong, ore is this really not yet supported?
Posted on 9/30/09 5:52 AM.
Hi Dennis, which version of liferay and Netbeans Portal Pack are you using? http://portalpack.netbeans.org/pp30/download302.html Is the latest with some bug fixes.
Posted on 9/30/09 7:18 AM in reply to Dennis Nes.
Anyone here who can send me the Plugins please emoticon
http://portalpack.netbeans.org/ is currently not available
I have installed my OS new and now i am missing the plugins :/

webaster {a} virtualizing.org
Posted on 11/4/09 8:04 PM.
^^ ups webmaster {a} virtualizing.org ;)
Posted on 11/4/09 8:04 PM in reply to Darko Joseph Hojnik.
http://blogs.sun.com/lukas/entry/page_not_found_at_netbeans
Posted on 11/4/09 9:41 PM in reply to Darko Joseph Hojnik.
hi Chetan
let me thanks for ur good work
now kaam ki baat
i m inplementing websynergy
now for blog I need to have modrator i.e. blogs need to go
to administraator before it is available to all
how can we do it
please suggest
Posted on 6/8/10 5:03 AM in reply to Santh Chetan Chadalavada.
Will the portal pack be updated to work with Liferay 6.0? Any idea of when? It's an indispensable tool, and currently the Eclipse IDE for Liferay 6 cannot edit Themes...
Posted on 8/3/10 2:57 PM in reply to Santh Chetan Chadalavada.
Hi Marcelo,

You should probably ask Oracle directly, we don't have information about it.

Regarding editing of themes in Liferay IDE I think it's already been worked on and will be available soon.
Posted on 8/4/10 1:17 AM in reply to Marcelo Ruiz Camauër.
Hello, thank you for the post. Just came across an introduction to creating Java applications with the NetBeans integrated development environment. It covers both using NetBeans with existing Java source code, and also using NetBeans to develop a Java program from scratch. Might be of great use for beginners. Regards!
Posted on 12/22/10 5:19 AM.
[...] Liferay Hook Plugin Support , Netbeans Portal Pack 3.0.2 – Blog – Liferay.com [...] Read More
Posted on 9/4/14 1:33 AM.