What You May Need to Know About Using Naming Containers

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. 5-16 Web User Interface Developers Guide for Oracle Application Development Framework Example 5–14 Server Listener Method for a Custom Client Event public void searchOnEnterClientEvent clientEvent { doRealSearchForFileItem; refresh search navigator this.refresh; }

3. Register the clientListener by dragging a Client Listener from the Operations

panel of the Component Palette, and dropping it as a child to the component that raises the event. 4. In the Insert Client Listener dialog, enter the method and type for the JavaScript function. Be sure to include a library name if the script is not included on the page. The type can be any string used to identify the custom event, for example, enterPressedOnSearch was used in the File Explorer.

5. Register the server listener by dragging a Server Listener from the Operations

panel of the Component Palette, and dropping it as a sibling to the clientListener tag. 6. In the Insert Server Listener dialog, enter the string used as the Type value for the client listener, as the value for this server listener, for example enterPressedOnSearch. In the Property Inspector, for the method attribute, enter an expression that resolves to the method created in Step 2.

5.4.2 What Happens at Runtime: How Client and Server Listeners Work Together

At runtime, when the user initiates the event, for example, pressing the Enter key, the client listener script executes. This script calls the AdfCustomEvent.queue method, and a custom event of the specified event type is queued on the input component. The server listener registered on the input component receives the custom event, and the associated bean method executes.

5.4.3 What You May Need to Know About Marshalling and Unmarshalling Data

Marshalling and unmarshalling is the process of converting data objects of a programming language into a byte stream and back into data objects that are native to the same or a different programming language. In ADF Faces, marshalling and unmarshalling refer to transformation of data into a suitable format so that it can be Note: The Java-to-JavaScript transformation can lose type information for Numbers, chars, Java Objects, arrays, and nonstring CharSequences. Therefore, if an object being sent to the server was initially on the server, you may want to add logic to ensure the correct conversion. See Section 5.4.3, What You May Need to Know About Marshalling and Unmarshalling Data. Note: On the component that will fire the custom client event, the clientComponent attribute must be set to true to ensure that a client-side generated component is available.