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:-

AddingStrutsAction.java

Explanation:-
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:-

 liferay-hook.xml

Explanation:-
In this xml we provide the path ie URL and implementing class. For hitting this URL we have to append c as:
http://localhost:8080/c/portal/liferayiseasy 

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:-
docroot\custom_jsps\html\portal\message.jsp

Our message.jsp contain just one line:-

message.jsp

and provide entry in liferay-hook.xml as:-
 <custom-jsp-dir>/custom_jsps</custom-jsp-dir>

when you deploy your hook this jsp is available in
"\tomcat-7.0.42\webapps\ROOT\html\portal".

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:-
auth.public.paths=/portal/liferayiseasy

Now finally your liferay-hook.xml become :-

liferay-hook.xml

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!