You can assign a JavaScript function
to a JavaServer Faces (JSF) control to serve as an event handler,
or you can remove an event handler from a control. 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 control using the onClick event
handler. When the control is clicked in the browser, the function
defined as the onClick event handler runs.
The JavaScript function
that is 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 that is
linked to the page. You cannot use an EGL function as an event handler
for a JSF control.
Follow these steps to assign or remove an event handler from a
JSF control:
- On a blank line inside a function in the JSF Handler, press Ctrl+Shift+Z.
The EGL Source Assistant window opens, displaying the JSF controls
on the page.
- In the EGL Source Assistant window, select the JSF image control
that you want to access.
- Click OK.
The EGL source assistant adds
two lines of EGL code to the JSF Handler. The first line defines an
EGL variable of the type that matches the JSF control that you selected.
The second line associates that variable with the JSF control. For
example, the code to access a JSF input text control might look like
this:
text1 HtmlInputText;
text1 = myViewRoot.findComponent("form1:text1");
- Using the EGL variable that the source assistant created, assign
or remove the event handlers. For example, to assign the JavaScript function myFunction() as
the onClick event handler for the text control, add
this code:
text1.setOnclick("myFunction");
To
remove an event handler from a JSF control, assign it a blank string
as an event handler:
text1.setOnclick("");