What You May Need to Know About Marshalling and Unmarshalling Data

5-18 Web User Interface Developers Guide for Oracle Application Development Framework Encoding for a table also uses JSON to pass push messages to the client. The following is an example of an envelope containing a single encoded push message: [{rKey:0,type:update,data:[{val:Active Data Every Second: on row 0:78,prop:value,cInd:0},{val:Active Data Every Second: on row 0:78,prop:value,cInd:1}]}] The envelope is a JavaScript Array with only one object, which describes the message. This message contains information about the type of change, the actual value of the data, and so on, that is then used by the client-side table peer to update the table itself. Table 5–6 shows the mapping between corresponding Java and JavaScript types. Note that there could be some loss of information during the conversion process. For example, say you are using the following custom event to send the number 1 and the String test, as shown in the following example: AdfCustomEvent.queueevent.getSource, something, {first:1, second:test}; In the server-side listener, the type of the first parameter would become a java.lang.Double because numbers are converted to Doubles when going from JavaScript to Java. However, it might be that the parameter started on the server side as an int, and was converted to a number when conversion from Java to JavaScript took place. Now on its return trip to the server, it will be converted to a Double.

5.5 Executing a Script Within an Event Response

Using the ExtendedRenderKitService class, you can add JavaScript to an event response, for example, after invoking an action method binding. It can be a simple message like sending an alert informing the user that the database connection could not be established, or a call to a function like hide on a popup window to programatically dismiss a popup dialog. For example, in the File Explorer application, when the user clicks the UpOneFolder navigation button to move up in the folder structure, the folder pane is repainted to Table 5–6 Java to JavaScript Type Map Java Type JavaScript Type java.lang.Boolean Boolean java.lang.Double Number java.lang.Integer Number java.lang.Float Number java.lang.Long Number java.lang.Short Number java.lang.Character String java.lang.CharSequence String java.util.Collection Array java.util.Date Date java.util.Map Object Array Array java.awt.Color TrColor Handling Events 5-19 display the parent folder as selected. The HandleUpOneFolder method is called in response to clicking the UpOneFolder button event. It uses the ExtendedRenderKitService class to add JavaScript to the response. Example 5–15 shows the UpOneFolder code in the page with the actionListener attribute bound to the HandleUpOneFolder handler method which will process the action event when the button is clicked. Example 5–15 Invoking a Method to Add JavaScript to a Response af:commandToolbarButton id=upOneFolder . . . actionListener={explorer.headerManager.handleUpOneFolder} Example 5–16 shows the handleUpOneFolder method that uses the ExtendedRenderKitService class. Example 5–16 Adding JavaScript to a Response public void handleUpOneFolderActionEvent actionEvent { UIXTree folderTree = feBean.getNavigatorManager.getFoldersNavigator.getFoldersTreeComponent; Object selectedPath = feBean.getNavigatorManager.getFoldersNavigator.getFirstSelectedTreePath; if selectedPath = null { TreeModel model = _feBean.getNavigatorManager.getFoldersNavigator.getFoldersTreeModel; Object oldRowKey = model.getRowKey; try { model.setRowKeyselectedPath; Object parentRowKey = model.getContainerRowKey; if parentRowKey = null { folderTree.getSelectedRowKeys.clear; folderTree.getSelectedRowKeys.addparentRowKey; This is an example of how to force a single attribute to rerender. The method assumes that the client has an optimized setter for selectedRowKeys of tree. FacesContext context = FacesContext.getCurrentInstance; ExtendedRenderKitService erks = Service.getRenderKitServicecontext, ExtendedRenderKitService.class; String clientRowKey = folderTree.getClientRowKeyManager. getClientRowKeycontext, folderTree, parentRowKey; String clientId = folderTree.getClientIdcontext; StringBuilder builder = new StringBuilder; builder.appendAdfPage.PAGE.findComponent; builder.appendclientId; builder.append.setSelectedRowKeys{; builder.appendclientRowKey; builder.append:true};; erks.addScriptcontext, builder.toString; } } finally { 5-20 Web User Interface Developers Guide for Oracle Application Development Framework model.setRowKeyoldRowKey; } Only really needed if using server-side rerendering of the tree selection, but performing it here saves a roundtrip just one, to fetch the table data, instead of one to process the selection event only after which the table data gets fetched _feBean.getNavigatorManager.getFoldersNavigator.openSelectedFolder; } }

5.6 Using Client Behavior Tags

ADF Faces client behavior tags provide declarative solutions to common client operations that you would otherwise have to write yourself using JavaScript, and register on components as client listeners. By using these tags instead of writing your own JavaScript code to implement the same operations, you reduce the amount of JavaScript code that needs to be downloaded to the browser. ADF Faces provides these client behavior tags that you can use in place of client listeners: ■ panelDashboardBehavior: Enables the runtime insertion of a child component into a panelDasboard component to appear more responsive. For details, see Section 8.7.1, How to Use the panelDashboard Component. ■ insertTextBehavior: Enables a command component to insert text at the cursor in an inputText component. For details, see Section 9.3.2, How to Add the Ability to Insert Text into an inputText Component. ■ richTextEditorInsertBehavior: Enables a command component to insert text including preformatted text at the cursor in a richTextEditor component. For details, see Section 9.8.2, How to Add the Ability to Insert Text into a richTextEditor Component. ■ showPopupBehavior: Enables a command component to launch a popup component. For details, see Section 13.4, Invoking Popup Elements. ■ showPrintablePageBehavior: Enables a command component to generate and display a printable version of the page. For details, see Section 33.2, Displaying a Page for Print. ■ scrollComponentIntoViewBehavior: Enables a command component to jump to a named component when clicked. For details, see Section 5.6.1, How to Use the scrollComponentIntoViewBehavior Tag. Client behavior tags cancel server-side event delivery automatically. Therefore, any actionListener or action attributes on the parent component will be ignored. This cannot be disabled. If you want to also trigger server-side functionality, you should use either a client-side event see Section 5.3, Using JavaScript for ADF Faces Client Events , or add an additional client listener that uses AdfCustomEvent and af:serverListener to deliver a server-side event see Section 5.4, Sending Custom Events from the Client to the Server .

5.6.1 How to Use the scrollComponentIntoViewBehavior Tag

Use the scrollComponentIntoViewBehavior tag when you want the user to be able to jump to a particular component on a page. This action is similar to an anchor in