How to Prevent Events from Propagating to the Server

5-14 Web User Interface Developers Guide for Oracle Application Development Framework The getSource method accesses the AdfUIComponent class, which can then be used to find the component. Example 5–11 JavaScript Using the findComponent Method function showPopupevent { event.cancel; var source = event.getSource; var popup = source.findComponentpopup; popup.show{align:after_end, alignId:button}; } When you use the findComponent method, the search starts locally at the component where the method is invoked. For more information about working with naming containers, see Section 3.5, Locating a Client Component on a Page.

5.4 Sending Custom Events from the Client to the Server

While the clientAttribute tag supports sending bonus attributes from the server to the client, those attributes are not synchronized back to the server. To send any custom data back to the server, use a custom event sent through the AdfCustomEvent class and the serverListener tag. The AdfCustomEvent.queue JavaScript method enables you to fire a custom event from any component whose clientComponent attribute is set to true. The custom event object contains information about the client event source and a map of parameters to include on the event. The custom event can be set for immediate delivery that is, during the Apply Request Values phase, or non-immediate delivery that is, during the Invoke Application phase. For example, in the File Explorer application, after entering a file name in the search field on the left, users can press the Enter key to invoke the search. As Example 5–12 shows, this happens because the inputText field contains a clientListener that invokes a JavaScript function when the Enter key is pressed. Example 5–12 clientListener Invokes JavaScript Function and Causes ServerLIstener to Be Invoked Code on the JSF page... af:inputText id=searchCriteriaName value={explorer.navigatorManager.searchNavigator. searchCriteriaName} shortDesc={explorerBundle[navigator.filenamesearch]} af:serverListener type=enterPressedOnSearch method={explorer.navigatorManager. searchNavigator.searchOnEnter} af:clientListener type=keyPress method=Explorer.searchNameHandleKeyPress af:inputText Code in JavaScript file... Explorer.searchNameHandleKeyPress = function event { if event.getKeyCode==AdfKeyStroke.ENTER_KEY { var source = event.getSource; AdfCustomEvent.queuesource, enterPressedOnSearch, Handling Events 5-15 {}, false; } } The JavaScript contains the AdfCustomEvent.queue method that takes the event source, the string enterPressedOnSearch as the custom event type, a null parameter map, and False for the immediate parameter. The inputText component on the page also contains the following serverListener tag: af:serverListener type=enterPressedOnSearch method={explorer.navigatorManager. searchNavigator.searchOnEnter} Because the type value enterPressedOnSearch is the same as the value of the parameter in the AdfCustomEvent.queue method in the JavaScript, the method that resolves to the method expression {explorer.navigatorManager.searchNavigator.searchOnEnter} will be invoked.

5.4.1 How to Send Custom Events from the Client to the Server

To send a custom event from the client to the server, fire the client event using a custom event type, write the server listener method on a backing bean, and have this method process the custom event. Next, register the server listener with the component. To send custom events: 1. Create the JavaScript that will handle the custom event using the AdfCustomEvent.queue method to provide the event source, custom event type, and the parameters to send to the server. For example, the JavaScript used to cause the pressing of the Enter key to invoke the search functionality uses the AdfCustomEvent.queue method that takes the event source, the string enterPressedOnSearch as the custom event type, a null parameter map, and False for the immediate parameter, as shown in Example 5–13 . Example 5–13 Sample JavaScript for Custom Events Explorer.searchNameHandleKeyPress = function event { if event.getKeyCode==AdfKeyStroke.ENTER_KEY { var source = event.getSource; AdfCustomEvent.queuesource, enterPressedOnSearch, {}, false; } } 2. Create the server listener method on a managed bean. This method must be public and take an oracle.adf.view.rich.render.ClientEvent object and return a void type. Example 5–14 shows the code used in the SearchNavigatorView managed bean that simply calls another method to execute the search and then refreshes the navigator.