HTML and CSS Reference
In-Depth Information
Listing 11-9.
JavaScript Hooking into the Event Listeners Exposed by the JSF JavaScript API
function outputAjaxEvent(data) {
console.log(data);
}
function outputError(errorData) {
console.log(errorData.type + " (" + errorData.status + "): " + errorName + ". " +
errorDescription);
// Register error on a remote error logging server
}
function showProgress(data) {
if (data.status === 'begin') {
toggle_visibility('in-progress');
} else if (data.status === 'success') {
toggle_visibility('in-progress');
}
}
// Utility function for toggling the visibility of an element
function toggle_visibility(id) {
var e = document.getElementById(id);
if (e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
jsf.ajax.addOnEvent(outputAjaxEvent);
jsf.ajax.addOnEvent(showProgress);
jsf.ajax.addOnError(outputError);
Listing 11-10.
Facelets Page Using the JavaScript File
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="
http://www.w3.org/1999/xhtml
"
xmlns:h="
http://xmlns.jcp.org/jsf/html
"
xmlns:ui="
http://xmlns.jcp.org/jsf/facelets
"
xmlns:f="
http://xmlns.jcp.org/jsf/core
"
>
<ui:composition template="/base.xhtml">
<ui:define name="title">
Chapter 11 - JavaScript API Demo
</ui:define>