run action on portlet load

Hi,

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?

Thanks,
Bruno

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.

Hi BJCO,

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

    IPortletURL myPortletURL = createActionUrl();
    myPortletURL.clearParameters();
    myPortletURL.clearState();
    // call action when navigation
    myPortletURL.setTargetAction("#{activePageBean.myAction}");

br,
Vlad

Eric,

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]http://techcommunity.softwareag.com/ecosystem/documentation/webmethods/wmsuites/wmsuite8-2_sp2/My_webMethods/8-2-SP1_CAF_and_MWS_Java_API_Reference/com/webmethods/caf/faces/bean/BasePortletPageBean.html[/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)
	 */
	@Override
	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()
	 */
	@Override
	protected void beforeRenderResponse() {
		// TODO do any additional work before the portlet is rendered

		super.beforeRenderResponse();
	}
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:

com.webmethods.caf.faces.component.util.ComponentUtils.isAsyncRefresh(getFacesContext());

Eric,

That looks pretty groovy. Thank you!

Lucas.

I decided to do this:


@Override 
protected void beforeRenderResponse() { 
if (com.webmethods.caf.faces.component.util.ComponentUtils.isAsyncRequest(getFacesContext()) == false)
{
resetPageFlowStorage();
}
super.beforeRenderResponse(); 
}

It’s working well for me, so far.

Thanks Eric.

@Anonymous:
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,
Marcus