Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Sam E
Hook an Action class. - Please suggest.
July 8, 2010 6:42 AM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

Hi,

With liferay 5.2.3, how to use Hook-Plugin to override an Action class eg. CreateAccountAction?

I come up with the following idea:

<event>
<event-class>au.com.xyz.MyCreateAccountAction</event-class>
<event-type>????</event-type>
</event>

I dont' know what event-type I should use here.
And what else do I need to use in hook for overriding an Action class?

Any simple example and suggestion is highly appreciated.

Thanks
Sam
Sam E
RE: Hook an Action class. - Please suggest.
July 8, 2010 7:25 AM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

In my portal-ext.properties file, I added the following line for referencing my own CreateAccountAction class:

captcha.check.portal.create_account=au.com.xyz.SamplePostLogin


When I delpoyed the portlet, it is successfully.
But creating account still calling the old CreateAccountAction class in liferay.

What is the correct way create this Hook?

Your suggestion is highly appreciated.

Thanks
Sam
Sam E
RE: Hook an Action class. - Please suggest.
July 8, 2010 7:45 AM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

Hi,

I have just tested the following setup, the deployment thrown error exception:

 1
 2
 314:42:17,668 INFO  [HookAutoDeployListener:59] Web plugin for C:\liferay\bundles\liferay-portal-5.2.3\deploy\customjsp-hook-5.2.3.1.war copied successfully. Deployment will start in a few seconds.
 414:42:20,189 INFO  [HookHotDeployListener:442] Hook for customjsp-hook was unregistered
 514:42:20,382 INFO  [HookHotDeployListener:184] Registering hook for customjsp-hook
 614:42:20,385 ERROR [HotDeployUtil:111] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for customjsp-hook
 7com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for customjsp-hook
 8        at com.liferay.portal.deploy.hot.BaseHotDeployListener.throwHotDeployException(BaseHotDeployListener.java:58)
 9        at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:101)
10        at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._doFireDeployEvent(HotDeployUtil.java:108)
11        at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._fireDeployEvent(HotDeployUtil.java:153)
12        at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:43)
13        at com.liferay.portal.kernel.servlet.HookContextListener.contextInitialized(HookContextListener.java:47)
14        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
15        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
16        at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1116)
17        at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1214)
18        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:293)
19        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
20        at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
21        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
22        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
23        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
24        at java.lang.Thread.run(Thread.java:595)
25Caused by: com.liferay.portal.kernel.xml.DocumentException: Error on line 7 of document  : The content of element type "hook" must match "(portal-properties?,language-properties*,custom-jsp-dir?)". Nested exception: The content of element type "hook" must match "(portal-properties?,language-properties*,custom-jsp-dir?)".
26        at com.liferay.portal.xml.SAXReaderImpl.read(SAXReaderImpl.java:377)
27        at com.liferay.portal.xml.SAXReaderImpl.read(SAXReaderImpl.java:388)
28        at com.liferay.portal.kernel.xml.SAXReaderUtil.read(SAXReaderUtil.java:156)
29        at com.liferay.portal.deploy.hot.HookHotDeployListener.doInvokeDeploy(HookHotDeployListener.java:191)
30        at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:98)


My liferay-hook.xml:
1
2
3<hook>
4    <custom-jsp-dir>/WEB-INF/jsps</custom-jsp-dir>
5    <portal-properties>portal.properties</portal-properties>
6</hook>


portal.properties file:

1
2
3captcha.check.portal.create_account=com.sun.test.SamplePostLogin


What is wrong with this implementation?

Thank you for any suggestion and help.

Sam.
Sam E
RE: Hook an Action class. - Please suggest.
July 8, 2010 2:46 PM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

Is there any reference and guideline explained the <event-types> about overriding the CreateAccountAction class, Password confirmation process, etc?

Your help is very much appreciated.

Thanks
Sam
Charles de Courval
RE: Hook an Action class. - Please suggest.
January 11, 2011 6:09 AM
Answer

Charles de Courval

Rank: Junior Member

Posts: 55

Join Date: July 31, 2010

Recent Posts

Hi Sam,
As far as I can tell, in Liferay 6.0.5, the only was that I was able to override and action class, in my case the com.liferay.portlet.enterpriseadmin.action.EditUserAction, was to create and ext plugin and override it there.

To do so, I had to create the overriding class in ext-impl/src and also add the struts definition in ext-web/docroot/WEB-INF/struts-config-ext.xml
1<struts-config>
2    <action-mappings>
3        <action path="/admin_server/edit_user" type="com.liferay.portlet.enterpriseadmin.action.EditUserAction">
4            <forward name="portlet.enterprise_admin.edit_user" path="portlet.directory.view_user" />
5            <forward name="portlet.enterprise_admin.error" path="portlet.directory.error" />
6        </action>
7    </action-mappings>
8</struts-config>

Hope that this helps.
cheers
Luis Rodríguez Fernández
RE: Hook an Action class. - Please suggest.
March 8, 2011 12:36 AM
Answer

Luis Rodríguez Fernández

Rank: Junior Member

Posts: 86

Join Date: June 26, 2009

Recent Posts

Hi Sam,

I am extending the /announcements/edit_entry action implementing a hook. I have created a hook project and in the src folder I have my implementation of the com.liferay.portlet.announcements.action.EditEntryAction that's all.

If you need to catch an event you have to tell the hook what event you want to catch.i.e: in your liferay-hook.xml you could have:

1<hook>
2    <portal-properties>portal-hook.properties</portal-properties>
3</hook>


And in this properties, located in your src folder, you could declare all the events that do you want to catch:

1login.events.post = your.package.name.AfterLoginAction


By the way do you think a hook is the best way for extending an action of the portal's core? I think that it is the easy and fastest way, but I am having problems for debug my code... Maybe I should do it via the EXT?

Hope it helps,

Luis

ps: I am afraid that there is no official guide for this stuff...
Luis Rodríguez Fernández
RE: Hook an Action class. - Please suggest.
March 8, 2011 11:42 PM
Answer

Luis Rodríguez Fernández

Rank: Junior Member

Posts: 86

Join Date: June 26, 2009

Recent Posts

Hi sam, Hi Charles,

Finally I also have extended the /alerts/edit_entry action through the EXT enviroment. The hook solution seemed to work but when I was debugging seemed that the source code was not synchronized with the server, maybe this solution is not the best approach for overriding an action...

Thanks,

Luis
Gianluca Pindinelli
RE: Hook an Action class. - Please suggest.
May 13, 2011 6:14 AM
Answer

Gianluca Pindinelli

Rank: Junior Member

Posts: 33

Join Date: March 17, 2010

Recent Posts

Luis Rodríguez Fernández:
Hi Sam,

I am extending the /announcements/edit_entry action implementing a hook. I have created a hook project and in the src folder I have my implementation of the com.liferay.portlet.announcements.action.EditEntryAction that's all. .


Hi Luis,
can you explain how you implement the hook?
I'm searching for extends document_library functionalities: is possible with an hook or I have to implement an ext plugin?

This page explain a solution: have you followed this workaround?

Thanks in advance!