Author: nbelaevski
Date: 2008-03-17 23:27:32 -0400 (Mon, 17 Mar 2008)
New Revision: 6885
Added:
trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/available.js
Modified:
trunk/framework/impl/src/main/java/org/richfaces/component/util/HtmlUtil.java
Log:
http://jira.jboss.com/jira/browse/RF-2344
Modified: trunk/framework/impl/src/main/java/org/richfaces/component/util/HtmlUtil.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/component/util/HtmlUtil.java 2008-03-18
03:27:25 UTC (rev 6884)
+++
trunk/framework/impl/src/main/java/org/richfaces/component/util/HtmlUtil.java 2008-03-18
03:27:32 UTC (rev 6885)
@@ -25,6 +25,7 @@
import java.util.regex.Pattern;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import org.ajax4jsf.renderkit.RendererUtils;
@@ -35,7 +36,12 @@
*
*/
public class HtmlUtil {
- public static String qualifySize(String sizeDeclaration) {
+
+ private static final String ORG_RICHFACES = "org.richfaces.";
+
+ private static final String ORG_AJAX4JSF = "org.ajax4jsf.";
+
+ public static String qualifySize(String sizeDeclaration) {
String trimmedValue = sizeDeclaration.trim();
if (trimmedValue.length() != 0) {
char lastChar = trimmedValue.charAt(trimmedValue.length() - 1);
@@ -96,6 +102,22 @@
return buffer.toString();
}
+ public static boolean shouldWriteId(UIComponent component) {
+ String rendererType = component.getRendererType();
+
+ String id = component.getId();
+ if (id != null && !id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) {
+
+ return true;
+ }
+
+ if (rendererType != null &&
+ (rendererType.startsWith(ORG_AJAX4JSF) || rendererType.startsWith(ORG_RICHFACES)))
{
+
+ return true;
+ }
+
+ return false;
+ }
-
}
Added:
trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/available.js
===================================================================
---
trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/available.js
(rev 0)
+++
trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/available.js 2008-03-18
03:27:32 UTC (rev 6885)
@@ -0,0 +1,145 @@
+//Requires prototype.js & AJAX script
+if (!document.observe) {
+ throw "prototype.js is required!";
+}
+
+if (!A4J || !A4J.AJAX || !A4J.AJAX.AddListener) {
+ throw "AJAX script is required!";
+}
+
+if (!window.Richfaces) {
+ window.Richfaces = {};
+}
+
+Object.extend(Richfaces, function() {
+ var _queueLength = 0;
+ var _available = {};
+ var _pollingActivated = false;
+
+ var _lastEltId = null;
+
+ var executeCallback = function(elt, callbacks) {
+ if (callbacks instanceof Array) {
+ for (var i = 0; i < callbacks.length; i++) {
+ callbacks[i](elt);
+ }
+ } else {
+ callbacks(elt);
+ }
+ };
+
+ var stopPolling = function() {
+ if (_pollingActivated) {
+ Event.stopObserving(document, "mouseover", onEvent, true);
+ Event.stopObserving(document, "focus", onEvent, true);
+ Event.stopObserving(document, "focusin", onEvent, true);
+
+ _pollingActivated = false;
+ _lastEltId = null;
+ }
+ }
+
+ var onEvent = function(event) {
+ var elt = Event.element(event);
+ while (elt) {
+ var id = elt.id;
+ if (id) {
+ if (!_lastEltId) {
+ _lastEltId = id;
+ } else if (_lastEltId == id) {
+ //we can stop now because elements queue hasn't changed since we've checked
this element
+ break;
+ }
+
+ var callbacks = _available[id];
+ if (callbacks) {
+ try {
+ executeCallback(elt, callbacks);
+ } catch (e) {
+ cleanup();
+ throw e;
+ }
+
+ delete _available[id];
+ if (--_queueLength == 0) {
+ stopPolling();
+ //done all elements for now
+ break;
+ }
+ }
+ }
+
+ elt = elt.parentNode;
+ }
+ };
+
+ var activatePolling = function() {
+ if (!_pollingActivated) {
+ Event.observe(document, "mousemove", onEvent, true);
+ Event.observe(document, "focus", onEvent, true);
+ Event.observe(document, "focusin", onEvent, true);
+
+ _pollingActivated = true;
+ }
+ };
+
+ var cleanup = function() {
+ try {
+ stopPolling();
+ _queueLength = 0;
+ _available = {};
+ } catch (e) {
+ LOG.error("Error occured during cleanup: " + e);
+ }
+ };
+
+
+ var onReady = function() {
+ try {
+ for (var id in _available) {
+ var elt = $(id);
+ if (elt) {
+ executeCallback(elt, _available[id]);
+ } else {
+ LOG.error("Element with id = " + id + " hasn't been
found!");
+ }
+ }
+ } finally {
+ cleanup();
+ }
+ };
+
+ var onAvailable = function(eltId, callback) {
+ var elt = $(eltId);
+ if (elt) {
+ callback(elt);
+ } else {
+ var a = _available[eltId];
+ if (!a) {
+ _available[eltId] = callback;
+
+ //reset cached element because we've just changed the queue
+ _lastEltId = null;
+
+ _queueLength++;
+ activatePolling();
+ } else {
+ if (a instanceof Array) {
+ a.push(callback)
+ } else {
+ var ar = new Array();
+ ar.push(a);
+ ar.push(callback);
+ _available[eltId] = ar;
+ }
+ }
+ }
+ };
+
+ A4J.AJAX.AddListener(onReady);
+ document.observe("dom:loaded", onReady);
+
+ return {
+ onAvailable: onAvailable
+ };
+}());