Does an Async Action trigger an Event?

Is there a generic event (not specific to any one control, but maybe to the whole document or the form) that occurs when an client side async action occurs? I’d like to be able to refresh a control (a messages panel) every time any button is pressed without having to manually set the refresh on every button.

In effect, I’d like to mimic how the CAF Message controls work.

Any thoughts are appreciated!

Lucas.

You should be able to listen for the CAF actionCompleteListener events using the OpenAjax hub (http://www.openajax.org/member/wiki/OpenAjax_Hub_1.0_Specification_PublishSubscribe).

For example, something like this in a Script Block control:


if (window.mysub == null) {
    //subscribe for action completion events
    window.mysub = OpenAjax.hub.subscribe("CAF.Command.actionCompleteListener.*", function(event, actionid) {
        //filter events to make sure it is originating from a form in the current portlet.

        if (actionid != null && actionid.startsWith("#{caf:cid('defaultForm')}") {
            alert("notified about action event inside the portlet form for: " + actionid);
        }
    });
}

if you want to see what events are firing, you could subscribe to them all and log it somewhere for inspection:

For example, if you are using firefox with firebug, then this javascript would log all the events to the firebug console:

OpenAjax.hub.subscribe("**", function(topic, data) {console.log(topic);});

Good stuff, Eric. Thanks once again.

My issue now (and this may be insurmountable) is that in my function I want to refresh a control, but I think since it is firing on actionComplete (and not refreshComplete) I’m getting an “…out of sync with server message”.

I’m just now sure how I can do this generically with out some coordination between the base portlet and the included portlet where this script would exist.

Thanks a million.