We can modify Liferay JSP, services, properties by using Hooks. One of the main use of Hook is we can override existing struts actionand also we can add custom struts action, these type of Hook is called as Liferay Struts Action Hook.
I'm taking here example of struts action "/login/login". Whenever we login in Liferay "com.liferay.portlet.login.action.LoginAction" is the action class that invokes. we're going to change this struts action by Struts Action Hook.
Follow the below steps to perform the change of Struts Action:
- Create Liferay Plugin Project of type Hook.
- Write the below code in liferay-hook.xml
<?xml version="1.0"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd">
<hook>
<struts-action>
<struts-action-path>/login/login</struts-action-path>
<struts-action-impl>com.evon.action.CustomLoginAction</struts-action-impl>
</struts-action>
</hook>
- CustomLoginAction.java
package com.evon.action;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import com.liferay.portal.kernel.struts.BaseStrutsPortletAction;
import com.liferay.portal.kernel.struts.StrutsPortletAction;
public class CustomLoginAction extends BaseStrutsPortletAction{
@Override
public void processAction(StrutsPortletAction originalStrutsPortletAction,
PortletConfig portletConfig, ActionRequest actionRequest,
ActionResponse actionResponse) throws Exception {
/**
* This is the custom process action
* Once you try to login this method will be invoked
* We can write our own logic here
* Invoke the original struts action at the end
*/
System.out.println("in Custom login........................");
originalStrutsPortletAction.processAction(
originalStrutsPortletAction, portletConfig, actionRequest,
actionResponse);
}
public String render(
StrutsPortletAction originalStrutsPortletAction,
PortletConfig portletConfig, RenderRequest renderRequest,
RenderResponse renderResponse)
throws Exception {
return originalStrutsPortletAction.render(
null, portletConfig, renderRequest, renderResponse);
}
}
- Deploy the Hook and try to login, this will invoke method of CustomLoginAction class.
Hope this will help you :)
0 Comment(s)