All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.richfaces-jsf-log.js Maven / Gradle / Ivy

There is a newer version: 4.3.7.Final
Show newest version
if (typeof jsf != 'undefined') {
	(function(jQuery, richfaces, jsf) {
	
		//JSF log adapter
		var identifyElement = function(elt) {
			var identifier = '<' + elt.tagName.toLowerCase();
			var e = jQuery(elt);
			if (e.attr('id')) {
				identifier += (' id=' + e.attr('id'));
			}
			if (e.attr('class')) {
				identifier += (' class=' + e.attr('class'));
			}
	
			identifier += ' ...>';
	
			return identifier;
		}
	
		var formatPartialResponseElement = function(logElement, responseElement) {
			var change = jQuery(responseElement);
	
			logElement.append("Element " + responseElement.nodeName + "");
			if (change.attr("id")) {
				logElement.append(document.createTextNode(" for id=" + change.attr("id")));
			}
	
			jQuery(document.createElement("br")).appendTo(logElement);
			jQuery("").appendTo(logElement).text(change.toXML());
			jQuery(document.createElement("br")).appendTo(logElement);
		}
	
		var formatPartialResponse = function(partialResponse) {
			var logElement = jQuery(document.createElement("span"));
			
			partialResponse.children().each(function() {
				var responseElement = jQuery(this);
				if (responseElement.is('changes')) {
					logElement.append("Listing content of response changes element:
"); responseElement.children().each(function() { formatPartialResponseElement(logElement, this); }); } else { formatPartialResponseElement(logElement, this); } }); return logElement; } var jsfAjaxLogAdapter = function(data) { try { var log = richfaces.log; var source = data.source; var type = data.type; var responseCode = data.responseCode; var responseXML = data.responseXML; var responseText = data.responseText; if (type != 'error') { log.info("Received '" + type + "' event from " + identifyElement(source)); if (type == 'beforedomupdate') { var partialResponse; if (responseXML) { partialResponse = jQuery(responseXML).children("partial-response"); } var responseTextEntry = jQuery("Server returned responseText: ").eq(1).text(responseText).end(); if (partialResponse && partialResponse.length) { log.debug(responseTextEntry); log.info(formatPartialResponse(partialResponse)); } else { log.info(responseTextEntry); } } } else { var status = data.status; log.error("Received '" + type + '@' + status + "' event from " + identifyElement(source)); log.error("[" + data.responseCode + "] " + data.errorName + ": " + data.errorMessage); } } catch (e) { //ignore logging errors } }; var eventsListener = richfaces.createJSFEventsAdapter({ begin: jsfAjaxLogAdapter, beforedomupdate: jsfAjaxLogAdapter, success: jsfAjaxLogAdapter, complete: jsfAjaxLogAdapter, error: jsfAjaxLogAdapter }); jsf.ajax.addOnEvent(eventsListener); jsf.ajax.addOnError(eventsListener); // }(jQuery, RichFaces, jsf)); };




© 2015 - 2024 Weber Informatics LLC | Privacy Policy