Fórumok

Hook an Action class. - Please suggest.

Sam Wan, módosítva 13 év-val korábban

Hook an Action class. - Please suggest.

Liferay Master Bejegyzések: 660 Csatlakozás dátuma: 2009.03.03. Legújabb bejegyzések
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 Wan, módosítva 13 év-val korábban

RE: Hook an Action class. - Please suggest.

Liferay Master Bejegyzések: 660 Csatlakozás dátuma: 2009.03.03. Legújabb bejegyzések
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 Wan, módosítva 13 év-val korábban

RE: Hook an Action class. - Please suggest.

Liferay Master Bejegyzések: 660 Csatlakozás dátuma: 2009.03.03. Legújabb bejegyzések
Hi,

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



14: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.
14:42:20,189 INFO  [HookHotDeployListener:442] Hook for customjsp-hook was unregistered
14:42:20,382 INFO  [HookHotDeployListener:184] Registering hook for customjsp-hook
14:42:20,385 ERROR [HotDeployUtil:111] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for customjsp-hook
com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for customjsp-hook
        at com.liferay.portal.deploy.hot.BaseHotDeployListener.throwHotDeployException(BaseHotDeployListener.java:58)
        at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:101)
        at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._doFireDeployEvent(HotDeployUtil.java:108)
        at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._fireDeployEvent(HotDeployUtil.java:153)
        at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:43)
        at com.liferay.portal.kernel.servlet.HookContextListener.contextInitialized(HookContextListener.java:47)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
        at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1116)
        at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1214)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:293)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
        at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
        at java.lang.Thread.run(Thread.java:595)
Caused 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?)".
        at com.liferay.portal.xml.SAXReaderImpl.read(SAXReaderImpl.java:377)
        at com.liferay.portal.xml.SAXReaderImpl.read(SAXReaderImpl.java:388)
        at com.liferay.portal.kernel.xml.SAXReaderUtil.read(SAXReaderUtil.java:156)
        at com.liferay.portal.deploy.hot.HookHotDeployListener.doInvokeDeploy(HookHotDeployListener.java:191)
        at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:98)




My liferay-hook.xml:


<hook>
	<custom-jsp-dir>/WEB-INF/jsps</custom-jsp-dir>
	<portal-properties>portal.properties</portal-properties>
</hook>


portal.properties file:



captcha.check.portal.create_account=com.sun.test.SamplePostLogin


What is wrong with this implementation?

Thank you for any suggestion and help.

Sam.
Sam Wan, módosítva 13 év-val korábban

RE: Hook an Action class. - Please suggest.

Liferay Master Bejegyzések: 660 Csatlakozás dátuma: 2009.03.03. Legújabb bejegyzések
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
thumbnail
charles de courval, módosítva 13 év-val korábban

RE: Hook an Action class. - Please suggest.

Junior Member Bejegyzések: 55 Csatlakozás dátuma: 2010.07.31. Legújabb bejegyzések
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
<struts-config>
	<action-mappings>
		<action path="/admin_server/edit_user" type="com.liferay.portlet.enterpriseadmin.action.EditUserAction">
			<forward name="portlet.enterprise_admin.edit_user" path="portlet.directory.view_user" />
			<forward name="portlet.enterprise_admin.error" path="portlet.directory.error" />
		</action>
	</action-mappings>
</struts-config>

Hope that this helps.
cheers
thumbnail
Luis Rodríguez Fernández, módosítva 13 év-val korábban

RE: Hook an Action class. - Please suggest.

Junior Member Bejegyzések: 86 Csatlakozás dátuma: 2009.06.26. Legújabb bejegyzések
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
thumbnail
Luis Rodríguez Fernández, módosítva 13 év-val korábban

RE: Hook an Action class. - Please suggest.

Junior Member Bejegyzések: 86 Csatlakozás dátuma: 2009.06.26. Legújabb bejegyzések
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:

<hook>
	<portal-properties>portal-hook.properties</portal-properties>
</hook>


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

login.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...
thumbnail
Gianluca Pindinelli, módosítva 12 év-val korábban

RE: Hook an Action class. - Please suggest.

Junior Member Bejegyzések: 33 Csatlakozás dátuma: 2010.03.17. Legújabb bejegyzések
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!