留言板

Running action when page loads

Ralf Haller,修改在8 年前。

Running action when page loads

Junior Member 帖子: 54 加入日期: 13-5-13 最近的帖子
Hi,

I am looking for a solution to run an action once (and only once) before a page is loaded. Using servlet events (servlet.service.events.pre) does not work, since these actions run multiple times.

Any ideas?

Ralf
thumbnail
David H Nebinger,修改在8 年前。

RE: Running action when page loads

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
What, you mean like a startup action when the portlet is started at container startup?

Servlet.service.events.pre is invoked before every service event, that includes every action, render, resource, etc., event.

Otherwise you can use spring bean initializers if you're using spring, heck even class constructors can achieve the same. Portlet classes also have init() methods so you can extend whatever portlet class you're currently using and override it's init() method to add your own initialization for the portlet.

All of these break down if you're talking about running this once for each portlet instance, though, so I don't know how to truly answer your question without more context.