How to ensure custom serverListener events fires before action events

Using JavaScript in ADF Faces you can queue custom events defined by an af:serverListener tag. If the custom event however is queued from an af:clientListener on a command component, then the command component's action and action listener methods fire before the queued custom event. If you have a use case, for example in combination with client side integration of 3rd party technologies like HTML, Applets or similar, then you want to change the order of execution.

The way to change the execution order is to invoke the command item action from the client event method that handles the custom event propagated by the af:serverListener tag. The following four steps ensure your successful doing this

1.       Call cancel() on the event object passed to the client JavaScript function invoked by the af:clientListener tag

2.       Call the custom event as an immediate action by setting the last argument in the custom event call to true

function invokeCustomEvent(evt){
  evt.cancel();       
  var custEvent = new AdfCustomEvent(
                        evt.getSource(),
                        "mycustomevent",                                                                                           
                        {message:"Hello World"},
                        true);
   custEvent.queue();
}

3.       When handling the custom event on the server, lookup the command item, for example a button, to queue its action event. This way you simulate a user clicking the button. Use the following code

ActionEvent event = new ActionEvent(component);
event.setPhaseId(PhaseId.INVOKE_APPLICATION);
event.queue();

The component reference needs to be changed with the handle to the command item which action method you want to execute.

4.       If the command component has behavior tags, like af:fileDownloadActionListener, or af:setPropertyListener, defined, then these are also executed when the action event is queued. However, behavior tags, like the file download action listener, may require a full page refresh to be issued to work, in which case the custom event cannot be issued as a partial refresh.

File download action tag:
http://download.oracle.com/docs/cd/E17904_01/apirefs.1111/e12419/tagdoc/af_fileDownloadActionListener.html

" Since file downloads must be processed with an ordinary request - not XMLHttp AJAX requests - this tag forces partialSubmit to be false on the parent component, if it supports that attribute."

To issue a custom event as a non-partial submit, the previously shown sample code would need to be changed as shown below

function invokeCustomEvent(evt){
  evt.cancel();       
  var custEvent = new AdfCustomEvent(
                        evt.getSource(),
                        "mycustomevent",                                                                                           
                        {message:"Hello World"},
                        true);
   custEvent.queue(false);
}

To learn more about custom events and the af:serverListener, please refer to the tag documentation:

http://download.oracle.com/docs/cd/E17904_01/apirefs.1111/e12419/tagdoc/af_serverListener.html

Comments:

Post a Comment:
Comments are closed for this entry.
About

The Oracle JDeveloper forum ranks in the Top 5 of the most active forums on the Oracle Technology Network (OTN).



The OTN Harvest blog is a summary of selected topics posted on the OTN Oracle JDeveloper forum.



It is an effort to turn knowledge exchange into an interesting read for developers who enjoy little nuggets of wisdom





Frank Nimphius

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today