Friday, April 24, 2015

Adding Struts Action by Hook in Liferay

Today we will discuss about Adding Struts action in Liferay by using Hook.Before reading this blog you must read my previous blog on  Override Struts Action by Hook in Liferay. Adding Struts action is similar to overriding Struts Action but the difference is :-

For Overriding we extends BaseStrutsPortletAction Class.
For Adding we extends BaseStrutsAction Class.

So lets start step by step:-

Step 1:-Create Liferay hook project
File-->New-->Liferay Plugin Project-->Provide name-->Select hook in plugin type-->Finish.
You can see snapshot in my previous article (Step 1)   Portal Properties Hook in Liferay.

Step 2:-Create Action Class
Create a package com.aditya.demo inside src and than create a class as:-

In this class we extend BaseStrutsAction class and just provide path of jsp.

Step 3:-Create entry in liferay-hook.xml
Provide the entry of your action class in liferay-hook.xml:-


In this xml we provide the path ie URL and implementing class. For hitting this URL we have to append c as:

Step 4:-Create required jsp
Create a jsp hook for the jsp as we return our path from action class as "/portal/message.jsp".

So create a structure in docroot as:-

Our message.jsp contain just one line:-


and provide entry in liferay-hook.xml as:-

when you deploy your hook this jsp is available in

That's it when you hit "http://localhost:8080/c/portal/liferayiseasy" liferay show login page provide credential and you can see 
message .jsp.When you hit the URL and you don't want to provide the credential just make the URL public by property hook.

Step 5:-Make URL to public
Just create Portal Property Hook and override auth.public.paths as:-

Now finally your liferay-hook.xml become :-


For detail of how to create Portal Properties hook you may follow my previous blog Portal Property Hook in Liferay

That's it hit "http://localhost:8080/c/portal/liferayiseasy" and you see output as:-
Welcome here Aditya Bhardwaj

Project Structure

You can Download Source code from Adding Struts Action Hook in Liferay

Hope this will Help....

Related Post:-

No comments:

Post a Comment

Total Pageviews

Number Of Unique Visitor

Free counters!