Author: nbelaevski
Date: 2009-08-24 12:48:06 -0400 (Mon, 24 Aug 2009)
New Revision: 15283
Modified:
root/examples/trunk/components/core-demo/src/main/webapp/status.xhtml
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js/4_0_0.js
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java
Log:
Named status support added
Modified: root/examples/trunk/components/core-demo/src/main/webapp/status.xhtml
===================================================================
--- root/examples/trunk/components/core-demo/src/main/webapp/status.xhtml 2009-08-24
16:24:55 UTC (rev 15282)
+++ root/examples/trunk/components/core-demo/src/main/webapp/status.xhtml 2009-08-24
16:48:06 UTC (rev 15283)
@@ -14,6 +14,9 @@
jQuery(source).css('border', borderStyle);
}
</script>
+
+ <a4j:status name="ilStatus" startText="...named status request
start..." />
+ <br />
<a4j:status startStyle="color: green" errorStyle="color: red"
onstart="selectEventSource(event.source, '3px dotted navy')"
onerror="selectEventSource(event.source, '2px solid red')"
onsuccess="selectEventSource(event.source, '0px none white')">
@@ -30,6 +33,10 @@
</a4j:status>
<h:form>
+ <a4j:jsFunction name="statusFunction" status="ilStatus"
action="#{statusBean.delay}" />
+
+ <h:commandLink value="Named status" onclick="statusFunction();
return false;" />
+  
<h:commandLink value="Ajax" action="#{statusBean.delay}">
<f:ajax />
</h:commandLink>
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2009-08-24
16:24:55 UTC (rev 15282)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2009-08-24
16:48:06 UTC (rev 15283)
@@ -27,7 +27,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@@ -36,7 +35,6 @@
import java.util.Map;
import java.util.Set;
-import javax.faces.component.EditableValueHolder;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.component.UIForm;
@@ -55,7 +53,6 @@
import org.ajax4jsf.component.AjaxComponent;
import org.ajax4jsf.component.AjaxContainer;
import org.ajax4jsf.component.AjaxLoadBundleComponent;
-import org.ajax4jsf.component.AjaxSupport;
import org.ajax4jsf.component.AjaxViewRoot;
import org.ajax4jsf.component.JavaScriptParameter;
import org.ajax4jsf.context.AjaxContext;
@@ -294,6 +291,12 @@
UIComponent component) {
AjaxEventOptions ajaxEventOptions = new AjaxEventOptions();
+
+ String ajaxStatusName = getAjaxStatus(component);
+ if (ajaxStatusName != null && ajaxStatusName.length() != 0) {
+ ajaxEventOptions.set(STATUS_ATTR_NAME, ajaxStatusName);
+ }
+
appendParameters(facesContext, component, ajaxEventOptions.getParameters());
return ajaxEventOptions;
@@ -661,20 +664,23 @@
} else {
statusId = (String) component.getAttributes().get(STATUS_ATTR_NAME);
}
- if (null != statusId) {
- UIComponent status = RendererUtils.getInstance().
- findComponentFor(component, statusId);
-
- if (null != status) {
- statusId = status
- .getClientId(FacesContext.getCurrentInstance());
- } else {
- log.warn(Messages.getMessage(
- Messages.AJAX_STATUS_COMPONENT_NOT_FOWND_WARNING,
- component.getId()));
- }
- }
+
return statusId;
+
+// if (null != statusId) {
+// UIComponent status = RendererUtils.getInstance().
+// findComponentFor(component, statusId);
+//
+// if (null != status) {
+// statusId = status
+// .getClientId(FacesContext.getCurrentInstance());
+// } else {
+// log.warn(Messages.getMessage(
+// Messages.AJAX_STATUS_COMPONENT_NOT_FOWND_WARNING,
+// component.getId()));
+// }
+// }
+// return statusId;
}
public static JSFunctionDefinition buildAjaxOncomplete(String body) {
Modified:
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js/4_0_0.js
===================================================================
---
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js/4_0_0.js 2009-08-24
16:24:55 UTC (rev 15282)
+++
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js/4_0_0.js 2009-08-24
16:48:06 UTC (rev 15283)
@@ -308,6 +308,56 @@
}
};
+ var jsfEventsAdapterEventNames = {
+ event: {
+ 'begin': ['onsubmit'],
+ 'success': ['onsuccess', 'oncomplete']
+ },
+ error: ['onerror', 'oncomplete']
+ };
+
+ richfaces.createJSFEventsAdapter = function(handlers) {
+ //hash of handlers
+ //supported are:
+ // - onsubmit
+ // - onsuccess
+ // - onerror
+ // - oncomplete
+ handlers = handlers || {};
+
+ return function(eventData) {
+ var source = eventData.source;
+ //that's request status, not status control data
+ var status = eventData.status;
+ var type = eventData.type;
+
+ var typeHandlers = jsfEventsAdapterEventNames[type];
+ var handlerNames = (typeHandlers || {})[status] || typeHandlers;
+
+ if (handlerNames) {
+ for (var i = 0; i < handlerNames.length; i++) {
+ var handler = handlers[handlerNames[i]];
+ if (handler) {
+ handler.call(source, eventData);
+ }
+ }
+ }
+ };
+ };
+
+ var setGlobalStatusNameVariable = function(statusName) {
+ //TODO: parallel requests
+ if (statusName) {
+ richfaces['statusName'] = statusName;
+ } else {
+ delete richfaces['statusName'];
+ }
+ }
+
+ var getGlobalStatusNameVariable = function() {
+ return richfaces.statusName;
+ }
+
richfaces.ajax = function(source, event, options) {
options = options || {};
var sourceId = (typeof source == 'object' && source.id) ? source.id :
source;
@@ -320,38 +370,50 @@
parameters.RICHFACES_AJAX = sourceId;
}
+ var eventsHandler;
+
+ if (options.status) {
+ eventsHandler = richfaces.createJSFEventsAdapter({
+ onsubmit: function() { setGlobalStatusNameVariable(options.status); }
+ });
+ }
+
parameters[sourceId] = sourceId;
+ if (eventsHandler) {
+ parameters['onevent'] = eventsHandler;
+ parameters['onerror'] = eventsHandler;
+ }
jsf.ajax.request(source, event, parameters);
};
var RICHFACES_AJAX_STATUS = "richfaces:ajaxStatus";
- var statusAjaxEventHandler = function(data) {
- var source = data.source;
- var status = data.status;
- var type = data.type;
-
- var methodName;
-
- if (type == 'event') {
- if (status == 'begin') {
- methodName = 'start';
- } else if (status == 'success') {
- methodName = 'success';
- }
- } else if (type == 'error') {
- methodName = 'error';
- }
-
+ var getStatusDataAttributeName = function(statusName) {
+ return statusName ? (RICHFACES_AJAX_STATUS + "@" + statusName) :
RICHFACES_AJAX_STATUS;
+ };
+
+ var statusAjaxEventHandler = function(data, methodName) {
if (methodName) {
+ //global status name
+ var statusName = getGlobalStatusNameVariable();
+ var source = data.source;
+
var statusApplied = false;
- var statusContainers = [jQuery(source).parents('form'), jQuery()];
+ var statusDataAttribute = getStatusDataAttributeName(statusName);
+
+ var statusContainers;
+ if (statusName) {
+ statusContainers = [jQuery()];
+ } else {
+ statusContainers = [jQuery(source).parents('form'), jQuery()];
+ }
+
for (var containerIdx = 0; containerIdx < statusContainers.length &&
!statusApplied;
containerIdx++) {
var statusContainer = statusContainers[containerIdx];
- var statuses = statusContainer.data(RICHFACES_AJAX_STATUS);
+ var statuses = statusContainer.data(statusDataAttribute);
if (statuses) {
for (var statusId in statuses) {
var status = statuses[statusId];
@@ -364,7 +426,7 @@
}
if (!statusApplied) {
- statusContainer.removeData(RICHFACES_AJAX_STATUS)
+ statusContainer.removeData(statusDataAttribute);
}
}
}
@@ -376,9 +438,16 @@
if (!thisFunction.initialized) {
thisFunction.initialized = true;
- jsf.ajax.addOnEvent(statusAjaxEventHandler);
+ var jsfEventsListener = richfaces.createJSFEventsAdapter({
+ onsubmit: function(eventData) { statusAjaxEventHandler(eventData, 'start');
},
+ onerror: function(eventData) { statusAjaxEventHandler(eventData, 'error');
},
+ onsuccess: function(eventData) { statusAjaxEventHandler(eventData,
'success'); },
+ oncomplete: function() { setGlobalStatusNameVariable(null); }
+ });
+
+ jsf.ajax.addOnEvent(jsfEventsListener);
//TODO blocks default alert error handler
- jsf.ajax.addOnError(statusAjaxEventHandler);
+ jsf.ajax.addOnError(jsfEventsListener);
}
};
@@ -414,15 +483,24 @@
return {
register: function() {
initializeStatuses();
- var container = getElement.call(this).parents('form');
- if (container.length == 0) {
+
+ var statusName = this.options.statusName;
+ var dataStatusAttribute = getStatusDataAttributeName(statusName);
+
+ var container;
+ if (statusName) {
container = jQuery();
- };
+ } else {
+ container = getElement.call(this).parents('form');
+ if (container.length == 0) {
+ container = jQuery();
+ };
+ }
- var statuses = container.data(RICHFACES_AJAX_STATUS);
+ var statuses = container.data(dataStatusAttribute);
if (!statuses) {
statuses = {};
- container.data(RICHFACES_AJAX_STATUS, statuses);
+ container.data(dataStatusAttribute, statuses);
}
statuses[this.statusId] = this;
Modified:
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java
===================================================================
---
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java 2009-08-24
16:24:55 UTC (rev 15282)
+++
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java 2009-08-24
16:48:06 UTC (rev 15283)
@@ -204,6 +204,8 @@
ScriptHashVariableWrapper.EVENT_HANDLER);
}
+ rendererUtils.addToScriptHash(options, "statusName",
attributes.get("name"));
+
if (!options.isEmpty()) {
statusConstructor.addParameter(options);
}