Setting event handlers for a JSF component

You can assign or remove a JavaScriptâ„¢ function to a JSF component to serve as an event handler. In this context, an event handler is a JavaScript function that is called when a specific event happens on the page. For example, you can assign a function to a text input field using the onClick event handler. When the field is clicked in the browser, the function defined as the onClick event handler runs.

The JavaScript function used as an event handler must be available to the page, either in a <script> tag on the page itself or in a script file linked to the page. You can not use an EGL function as an event handler for a JSF component.

This task has the following prerequisites. For more information, see Accessing a JSF component from a pageHandler.
Follow these steps to assign or remove an event handler from a JSF component:
  1. On a blank line inside a function in the pageHandler, press Ctrl+Shift+Z. The EGL Source Assistant window opens, displaying the JSF components on the page.
  2. In the EGL Source Assistant window, select the JSF image component you want to access.
  3. Click OK.
    The EGL source assistant adds two lines of EGL code to the pageHandler. The first line defines an EGL variable of the type that matches the JSF component that you selected. The second line associates that variable with the JSF component. For example, the code to access a JSF input text component might look like this:
    text1 HtmlInputText;
    text1 = myViewRoot.findComponent("form1:text1");
  4. Using the EGL variable created by the source assistant, assign or remove the event handlers. For example, to assign the JavaScript function myFunction() as the onClick event handler for the text field, add this code:
    text1.setOnclick("myFunction");
    To remove an event handler from a JSF component, assign it a blank string as an event handler:
    text1.setOnclick("");

Related concepts
JSF component tree
viewRootVar property

Related tasks
Adding JSF component interface support to an EGL Web project
Accessing a JSF component from a pageHandler
Changing the style class of a JSF component
Changing the style of a JSF component
Changing the target of a JSF link
Enabling or disabling JSF components
Setting the size of a JSF image
Setting JSF data table properties

Related reference
Component tree access parts

Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.