run action on portlet load


How can I run an action everytime the portlet loads?

I know I can set a web service to auto-refresh, but what if I need to run a method after the ws refresh?


You should be able to add your action to the ‚Äėinitialize‚Äô dataflow action of your page bean that runs the first time the portlet instance is rendered on the current page.

Right click on the ‚ÄėInitialize()‚Äô action in the Bindings view and select ‚ÄúData Flow Implementation‚Ķ‚ÄĚ to edit the steps of the dataflow.


If you are using a redirect with a PortletURL we can use the following:

    IPortletURL myPortletURL = createActionUrl();
    // call action when navigation



Other than using JS and a hidden action is there a good way to do this EVERY time the page loads/is refreshed?

1 Like

There are various methods you can override in your page bean to hook into the different places in the lifecycle of a request. See the javadocs @ [url][/url]

For example, to do something every time a workspace is loaded (by navigation, clicking a tab or a link in the leftnav):

	/* (non-Javadoc)
	 * @see com.webmethods.caf.faces.bean.BasePortletPageBean#beforeWorkspaceLoad(javax.portlet.ActionRequest, javax.portlet.ActionResponse, java.lang.String)
	public void beforeWorkspaceLoad(ActionRequest request,
			ActionResponse response, String navigationType) {
		// TODO do any additional work before the workspace loads
		super.beforeWorkspaceLoad(request, response, navigationType);

Or, to do something every time the portlet is rendered.

	/* (non-Javadoc)
	 * @see com.webmethods.caf.faces.bean.BaseViewBean#beforeRenderResponse()
	protected void beforeRenderResponse() {
		// TODO do any additional work before the portlet is rendered

1 Like

Thanks Eric. I guess what I want something that would only occur when the portlet is initially rendered, like in a browser refresh and the view bean has already been initialized. The beforeRenderResponse is firing on every GET (every action).

What it boils down to is I want to reinitialize the page (remove bindings, call the initialize method, etc) every time the portlet is initially rendered, not just after a Page Flow.

Does that make any sense?

The CAF framework can not automatically make assumptions about what the intent of the page refresh was.

Your use case seems similar to what the beforeWorkspaceLoad callback was intended to address. That callback method gets invoked whenever the user clicks a workspace tab (to reload the current workspace) or clicks the page link in the leftnav (to reload the page). The idea was that when the user clicks one of those links their intention would be to reload the page with all the data reset to the original state. If the user just refreshes the page for some other reason, it may not be appropriate to reset the state since the user could lose data they were working on.

One other possibility, in beforeRenderResponse you can check if this render is for a partial page refresh.

For example:



That looks pretty groovy. Thank you!


I decided to do this:

protected void beforeRenderResponse() { 
if (com.webmethods.caf.faces.component.util.ComponentUtils.isAsyncRequest(getFacesContext()) == false)

It’s working well for me, so far.

Thanks Eric.

More precisely the documentation of the BaseViewBean class, where most of those Portlet lifecycle-related methods (afterApplyRequestValues, afterInvokeApplication, afterProcessValidations, afterRenderResponse, afterRestoreView, afterUpdateModelValues, beforeApplyRequestValues, beforeInvokeApplication, beforeProcessValidations, beforeRenderResponse, beforeRestoreView, beforeUpdateModelValues) are defined and from which the BasePageBean class inherits them.

Best regards,