Author: nbelaevski
Date: 2010-03-29 10:39:03 -0400 (Mon, 29 Mar 2010)
New Revision: 16682
Added:
root/framework/trunk/api/src/main/java/org/richfaces/context/
root/framework/trunk/api/src/main/java/org/richfaces/context/ExtendedVisitContext.java
root/framework/trunk/api/src/main/java/org/richfaces/context/ExtendedVisitContextMode.java
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java
root/framework/trunk/impl/src/main/java/org/richfaces/component/UISequence.java
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextAjaxOutputTracker.java
root/framework/trunk/impl/src/main/resources/META-INF/components.faces-config.xml
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js
Log:
https://jira.jboss.org/jira/browse/RF-7856
Added:
root/framework/trunk/api/src/main/java/org/richfaces/context/ExtendedVisitContext.java
===================================================================
---
root/framework/trunk/api/src/main/java/org/richfaces/context/ExtendedVisitContext.java
(rev 0)
+++
root/framework/trunk/api/src/main/java/org/richfaces/context/ExtendedVisitContext.java 2010-03-29
14:39:03 UTC (rev 16682)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.context;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface ExtendedVisitContext {
+
+ public static final String SUB_COMPONENT_ID =
"org.richfaces.SubComponentId";
+
+ public ExtendedVisitContextMode getVisitMode();
+
+}
Added:
root/framework/trunk/api/src/main/java/org/richfaces/context/ExtendedVisitContextMode.java
===================================================================
---
root/framework/trunk/api/src/main/java/org/richfaces/context/ExtendedVisitContextMode.java
(rev 0)
+++
root/framework/trunk/api/src/main/java/org/richfaces/context/ExtendedVisitContextMode.java 2010-03-29
14:39:03 UTC (rev 16682)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.context;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public enum ExtendedVisitContextMode {
+
+ EXECUTE,
+ RENDER
+
+}
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java 2010-03-29
13:56:12 UTC (rev 16681)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java 2010-03-29
14:39:03 UTC (rev 16682)
@@ -63,6 +63,7 @@
import org.ajax4jsf.model.ExtendedDataModel;
import org.ajax4jsf.model.Range;
import org.ajax4jsf.model.SerializableDataModel;
+import org.richfaces.context.ExtendedVisitContext;
import org.richfaces.log.RichfacesLogger;
import org.slf4j.Logger;
@@ -155,17 +156,30 @@
setRowKey(context, rowKey);
if (isRowAvailable()) {
- Iterator<UIComponent> dataChildrenItr = dataChildren();
+ VisitResult result = VisitResult.ACCEPT;
- while (dataChildrenItr.hasNext()) {
- UIComponent dataChild = dataChildrenItr.next();
-
- if (dataChild.visitTree(visitContext, callback)) {
+ if (context instanceof ExtendedVisitContext) {
+ result = visitContext.invokeVisitCallback(UIDataAdaptor.this,
callback);
+ if (VisitResult.COMPLETE.equals(result)) {
visitResult = true;
return DataVisitResult.STOP;
}
}
+
+ if (VisitResult.ACCEPT.equals(result)) {
+ Iterator<UIComponent> dataChildrenItr = dataChildren();
+
+ while (dataChildrenItr.hasNext()) {
+ UIComponent dataChild = dataChildrenItr.next();
+
+ if (dataChild.visitTree(visitContext, callback)) {
+ visitResult = true;
+
+ return DataVisitResult.STOP;
+ }
+ }
+ }
}
return DataVisitResult.CONTINUE;
Modified: root/framework/trunk/impl/src/main/java/org/richfaces/component/UISequence.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/component/UISequence.java 2010-03-29
13:56:12 UTC (rev 16681)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/component/UISequence.java 2010-03-29
14:39:03 UTC (rev 16682)
@@ -27,9 +27,11 @@
import java.util.List;
import java.util.Map;
+import javax.el.ValueExpression;
import javax.faces.component.UINamingContainer;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
+import javax.faces.el.ValueBinding;
import javax.faces.model.ArrayDataModel;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
@@ -124,7 +126,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.richfaces.component.UIDataAdaptor#getRowKeyConverter()
*/
@@ -156,6 +158,7 @@
}
public void setValue(Object value) {
+ resetDataModel();
getStateHelper().put(PropertyKeys.value, value);
}
@@ -170,7 +173,7 @@
public int getRowIndex() {
return getExtendedDataModel().getRowIndex();
}
-
+
@Override
public void captureOrigValue(FacesContext faces) {
super.captureOrigValue(faces);
@@ -234,4 +237,21 @@
}
}
+ @Override
+ public void setValueBinding(String name, ValueBinding binding) {
+ if ("value".equals(name)) {
+ resetDataModel();
+ }
+
+ super.setValueBinding(name, binding);
+ }
+
+ @Override
+ public void setValueExpression(String name, ValueExpression binding) {
+ if ("value".equals(name)) {
+ resetDataModel();
+ }
+
+ super.setValueExpression(name, binding);
+ }
}
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextAjaxOutputTracker.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextAjaxOutputTracker.java 2010-03-29
13:56:12 UTC (rev 16681)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextAjaxOutputTracker.java 2010-03-29
14:39:03 UTC (rev 16682)
@@ -21,50 +21,127 @@
package org.richfaces.context;
-import org.ajax4jsf.component.AjaxOutput;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
-import javax.faces.context.FacesContext;
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
import javax.faces.event.AbortProcessingException;
+import javax.faces.event.PostAddToViewEvent;
+import javax.faces.event.PreRemoveFromViewEvent;
import javax.faces.event.SystemEvent;
import javax.faces.event.SystemEventListener;
-import java.util.ArrayList;
-import java.util.Collection;
+import org.ajax4jsf.component.AjaxOutput;
+
/**
* @author Nick Belaevski
*/
public class PartialViewContextAjaxOutputTracker implements SystemEventListener {
- private static final String AJAX_OUTPUT_COMPONENTS_SET_ATTRIBUTE =
PartialViewContextAjaxOutputTracker.class
- + ":AjaxOutputComponentsSet";
- static Collection<AjaxOutput> getAjaxOutputComponentsSet(FacesContext context)
{
- AttributesContext attributes = SingletonsContext.FACES_CONTEXT.get(context);
- Collection<AjaxOutput> components =
- (Collection<AjaxOutput>)
attributes.getAttribute(AJAX_OUTPUT_COMPONENTS_SET_ATTRIBUTE);
+ private static final String ATTRIBUTE_NAME =
"org.richfaces.AjaxOutputTracker";
- if (components == null) {
- components = new ArrayList<AjaxOutput>();
- attributes.setAttribute(AJAX_OUTPUT_COMPONENTS_SET_ATTRIBUTE, components);
+ private static Set<String> getTrackedChildrenSet(UIComponent component, boolean
create) {
+ Map<String, Object> attributes = component.getAttributes();
+
+ @SuppressWarnings("unchecked")
+ Set<String> trackedChildrenSet = (Set<String>)
attributes.get(ATTRIBUTE_NAME);
+ if (trackedChildrenSet == null && create) {
+ trackedChildrenSet = new HashSet<String>();
+ attributes.put(ATTRIBUTE_NAME, trackedChildrenSet);
}
- return components;
+ return trackedChildrenSet;
}
- /*
- * (non-Javadoc)
- * @see javax.faces.event.SystemEventListener#isListenerForSource(java.lang.Object)
- */
- public boolean isListenerForSource(Object source) {
- return source instanceof AjaxOutput;
+ private static void clearTrackedChildrenSet(UIComponent component) {
+ component.getAttributes().remove(ATTRIBUTE_NAME);
}
- /*
- * (non-Javadoc)
- * @see
javax.faces.event.SystemEventListener#processEvent(javax.faces.event.SystemEvent)
- */
+ static boolean hasNestedAjaxOutputs(UIComponent component) {
+ if (!isContainerComponent(component)) {
+ throw new IllegalArgumentException(component.toString());
+ }
+
+ Set<String> trackedChildrenSet = getTrackedChildrenSet(component, false);
+
+ return trackedChildrenSet != null && !trackedChildrenSet.isEmpty();
+ }
+
+ private static String getId(UIComponent component) {
+ String id = component.getId();
+ if (id == null) {
+ //TODO force clientId creation?
+ component.getClientId();
+ id = component.getId();
+ }
+ return id;
+ }
+
+ private static boolean isContainerComponent(UIComponent component) {
+ return component instanceof NamingContainer || component instanceof UIViewRoot;
+ }
+
+ private UIComponent findParentContainerComponent(UIComponent component) {
+ UIComponent c = component.getParent();
+ while (c != null && !isContainerComponent(c)) {
+ c = c.getParent();
+ }
+
+ return c;
+ }
+
+ private void componentAdded(UIComponent c) {
+ UIComponent child = c;
+ UIComponent parent;
+ while ((parent = findParentContainerComponent(child)) != null) {
+ Set<String> trackedChildrenSet = getTrackedChildrenSet(parent, true);
+ boolean updateNextParent = trackedChildrenSet.isEmpty();
+ trackedChildrenSet.add(getId(child));
+
+ if (!updateNextParent) {
+ break;
+ }
+
+ child = parent;
+ }
+ }
+
+ private void componentRemoved(UIComponent c) {
+ UIComponent child = c;
+ UIComponent parent;
+ while ((parent = findParentContainerComponent(child)) != null) {
+ Set<String> ajaxOutputSet = getTrackedChildrenSet(parent, false);
+ if (ajaxOutputSet != null) {
+ ajaxOutputSet.remove(getId(child));
+
+ if (ajaxOutputSet.isEmpty()) {
+ clearTrackedChildrenSet(parent);
+ } else {
+ break;
+ }
+ }
+
+ child = parent;
+ }
+ }
+
public void processEvent(SystemEvent event) throws AbortProcessingException {
- FacesContext facesContext = FacesContext.getCurrentInstance();
+ if (event instanceof PostAddToViewEvent) {
+ PostAddToViewEvent addToViewEvent = (PostAddToViewEvent) event;
+ componentAdded(addToViewEvent.getComponent());
+ } else if (event instanceof PreRemoveFromViewEvent) {
+ PreRemoveFromViewEvent removeFromViewEvent = (PreRemoveFromViewEvent) event;
+ componentRemoved(removeFromViewEvent.getComponent());
+ } else {
+ throw new IllegalArgumentException(event.toString());
+ }
+ }
- getAjaxOutputComponentsSet(facesContext).add((AjaxOutput) event.getSource());
+ public boolean isListenerForSource(Object source) {
+ return source instanceof AjaxOutput;
}
+
}
Modified:
root/framework/trunk/impl/src/main/resources/META-INF/components.faces-config.xml
===================================================================
---
root/framework/trunk/impl/src/main/resources/META-INF/components.faces-config.xml 2010-03-29
13:56:12 UTC (rev 16681)
+++
root/framework/trunk/impl/src/main/resources/META-INF/components.faces-config.xml 2010-03-29
14:39:03 UTC (rev 16682)
@@ -10,6 +10,10 @@
<application>
<system-event-listener>
<system-event-listener-class>org.richfaces.context.PartialViewContextAjaxOutputTracker</system-event-listener-class>
+ <system-event-class>javax.faces.event.PreRemoveFromViewEvent</system-event-class>
+ </system-event-listener>
+ <system-event-listener>
+ <system-event-listener-class>org.richfaces.context.PartialViewContextAjaxOutputTracker</system-event-listener-class>
<system-event-class>javax.faces.event.PostAddToViewEvent</system-event-class>
</system-event-listener>
</application>
Modified: root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js
===================================================================
---
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js 2010-03-29
13:56:12 UTC (rev 16681)
+++
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js 2010-03-29
14:39:03 UTC (rev 16682)
@@ -20,13 +20,13 @@
input = newInput.appendTo(form);
}
} else {
- input.val(parameterValue);
+ input.val(parameterValue);
}
-
+
input.each(function() {parameterInputs.push(this)});
}
}
-
+
//TODO: inline onsubmit handler is not triggered -
http://dev.jquery.com/ticket/4930
form.trigger("submit");
} finally {
@@ -35,15 +35,15 @@
}
};
//
-
+
//utils.js
jQuery.fn.toXML = function () {
var out = '';
-
+
if (this.length > 0) {
if (typeof XMLSerializer == 'function' ||
typeof XMLSerializer == 'object') {
-
+
var xs = new XMLSerializer();
this.each(function() { out += xs.serializeToString(this); });
} else if (this[0].xml !== undefined) {
@@ -52,16 +52,16 @@
this.each( function() { out += this; } );
}
}
-
+
return out;
};
-
+
richfaces.log = (function(jQuery) {
var LOG_LEVELS = {'debug': 1, 'info': 2, 'warn': 3,
'error': 4};
var LOG_LEVEL_COLORS = {'debug': 'darkblue', 'info':
'blue', 'warn': 'gold', 'error': 'red'};
- var DEFAULT_LOG_LEVEL = LOG_LEVELS['info'];
+ var DEFAULT_LOG_LEVEL = LOG_LEVELS['info'];
var currentLogLevel = DEFAULT_LOG_LEVEL;
-
+
var consoleInitialized = false;
var setLevel = function(level) {
@@ -71,11 +71,11 @@
}
clear();
};
-
+
var setLevelFromSelect = function(iLevel) {
currentLogLevel = iLevel || DEFAULT_LOG_LEVEL;
};
-
+
var clear = function() {
if (window.console && useBrowserConsole) {
window.console.clear();
@@ -84,7 +84,7 @@
console.children(".rich-log-contents").children().remove();
}
};
-
+
var getConsole = function() {
var console = jQuery('#richfaces\\.log');
if (console.length != 0) {
@@ -93,15 +93,15 @@
var clearBtn = console.children("button.rich-log-element");
if (clearBtn.length == 0) {
- clearBtn = jQuery("<button
class='rich-log-element'>Clear</button>").appendTo(console);
+ clearBtn = jQuery("<button type='button'
class='rich-log-element'>Clear</button>").appendTo(console);
}
clearBtn.click(clear);
-
+
var levelSelect = console.children("select.rich-log-element");
if (levelSelect.length == 0) {
levelSelect = jQuery("<select class='rich-log-element'
/>").appendTo(console);
}
-
+
if (levelSelect.children().length == 0) {
for (var level in LOG_LEVELS) {
jQuery("<option value='" + LOG_LEVELS[level]+
"'>" + level + "</option>").appendTo(levelSelect);
@@ -110,7 +110,7 @@
levelSelect.val(currentLogLevel);
levelSelect.change(function(event) { clear();
setLevelFromSelect(parseInt(jQuery(this).val(), 10)); return false;});
-
+
var consoleEntries = console.children(".rich-log-contents");
if (consoleEntries.length == 0) {
consoleEntries = jQuery("<div
class='rich-log-contents'></div>").appendTo(console);
@@ -120,30 +120,30 @@
return console;
};
-
+
var useBrowserConsole = false;
var AM_PM = /(\s*(?:a|p)m)$/i;
-
+
var getMessagePrefix = function(level) {
var date = new Date();
var formattedDate = date.toLocaleTimeString();
-
+
var ms = (date.getMilliseconds() + 1000).toString().substr(1);
if (AM_PM.test(formattedDate)) {
formattedDate = formattedDate.replace(AM_PM, "." + ms + "$1");
} else {
formattedDate += "." + ms;
}
-
+
return level + '[' + formattedDate.replace() + ']: ';
};
-
+
var appendConsoleEntry = function(level, messagePrefix, messageText, console) {
//TODO - cache jQuery("<element>")?
var newEntry =
jQuery(document.createElement("div")).appendTo(console.children(".rich-log-contents"));
jQuery("<span style='color: " + LOG_LEVEL_COLORS[level] +
"'></span>").appendTo(newEntry).text(messagePrefix);
-
+
var entrySpan = jQuery(document.createElement("span")).appendTo(newEntry);
if (typeof messageText != 'object' || !messageText.appendTo) {
entrySpan.text(messageText);
@@ -155,7 +155,7 @@
var appendBrowserConsoleEntry = function(level, text) {
window.console[level]();
};
-
+
var appendMessage = function(level, message) {
if (window.console && useBrowserConsole) {
var text = getMessagePrefix(level) + message;
@@ -168,7 +168,7 @@
}
}
};
-
+
var methods = {setLevel: setLevel, clear: clear};
for (var logLevel in LOG_LEVELS) {
var f = function(text) {
@@ -179,14 +179,14 @@
}
return methods;
}(jQuery));
-
+
/**
* Evaluates chained properties for the "base" object.
- * For example, window.document.location is equivalent to
+ * For example, window.document.location is equivalent to
* "propertyNamesString" = "document.location" and "base"
= window
* Evaluation is safe, so it stops on the first null or undefined object
- *
- * @param propertyNamesArray - array of strings that contains names of the properties to
evaluate
+ *
+ * @param propertyNamesArray - array of strings that contains names of the properties to
evaluate
* @param base - base object to evaluate properties on
* @return returns result of evaluation or empty string
*/
@@ -196,14 +196,14 @@
do {
result = result[propertyNamesArray[c++]];
} while (result && c != propertyNamesArray.length);
-
+
return result;
};
-
+
var VARIABLE_NAME_PATTERN_STRING = "[_A-Z,a-z]\\w*";
var VARIABLES_CHAIN = new
RegExp("^\\s*"+VARIABLE_NAME_PATTERN_STRING+"(?:\\s*\\.\\s*"+VARIABLE_NAME_PATTERN_STRING+")*\\s*$");
var DOT_SEPARATOR = /\s*\.\s*/;
-
+
richfaces.evalMacro = function(macro, base) {
var value = "";
// variable evaluation
@@ -211,8 +211,8 @@
// object's variable evaluation
var propertyNamesArray = jQuery.trim(macro).split(DOT_SEPARATOR);
value = richfaces.getValue(propertyNamesArray, base);
- if (!value) {
- value = richfaces.getValue(propertyNamesArray, window);
+ if (!value) {
+ value = richfaces.getValue(propertyNamesArray, window);
}
} else {
//js string evaluation
@@ -222,25 +222,25 @@
} else with (base) {
value = eval(macro) ;
}
- } catch (e) {
- richfaces.log.warn("Exception: " + e.message + "\n[" + macro +
"]");
+ } catch (e) {
+ richfaces.log.warn("Exception: " + e.message + "\n[" + macro +
"]");
}
}
- if (typeof value == 'function') {
- value = value(base);
+ if (typeof value == 'function') {
+ value = value(base);
}
//TODO 0 and false are also treated as null values
return value || "";
};
var ALPHA_NUMERIC_MULTI_CHAR_REGEXP = /^\w+$/;
-
+
richfaces.interpolate = function (placeholders, context) {
var contextVarsArray = new Array();
for (var contextVar in context) {
if (ALPHA_NUMERIC_MULTI_CHAR_REGEXP.test(contextVar)) {
- //guarantees that no escaping for the below RegExp is necessary
+ //guarantees that no escaping for the below RegExp is necessary
contextVarsArray.push(contextVar);
}
}
@@ -248,23 +248,23 @@
var regexp = new RegExp("\\{(" + contextVarsArray.join("|") +
")\\}", "g");
return placeholders.replace(regexp, function(str, contextVar) {return
context[contextVar];});
};
-
+
richfaces.clonePosition = function(element, baseElement, positioning, offset) {
-
+
};
//
var pushTracker = {};
-
+
richfaces.startPush = function(options) {
var clientId = options.clientId;
var pushResourceUrl = options.pushResourceUrl;
var pushId = options.pushId;
var interval = options.interval;
var ondataavailable = options.ondataavailable;
-
+
richfaces.stopPush(pushId);
-
+
pushTracker[pushId] = setTimeout(function() { // TODO: define this function in
richfaces object to avoid definition every time when call startPush
var ajaxOptions = {
type: "HEAD",
@@ -274,7 +274,7 @@
dataType: "text",
complete: function(xhr) {
var isPushActive = !!pushTracker[pushId];
-
+
//TODO may someone wish to stop push from dataavailable handler?
delete pushTracker[pushId];
@@ -292,11 +292,11 @@
}
}
};
-
+
if (options.timeout) {
ajaxOptions.timeout = options.timeout;
}
-
+
jQuery.ajax(ajaxOptions);
}, interval);
};
@@ -307,7 +307,7 @@
delete pushTracker[id];
}
};
-
+
var jsfEventsAdapterEventNames = {
event: {
'begin': ['begin'],
@@ -347,7 +347,7 @@
if (type != 'error') {
delete event.status;
}
-
+
handler.call(source, event);
}
}
@@ -365,9 +365,9 @@
}
var getGlobalStatusNameVariable = function() {
- return richfaces.statusName;
+ return richfaces.statusName;
}
-
+
var chain = function() {
var functions = arguments;
if (functions.length == 1) {
@@ -379,7 +379,7 @@
var f = functions[i];
callResult = f.apply(this, arguments);
}
-
+
return callResult;
};
}
@@ -391,20 +391,20 @@
var curry = function(g, a) {
var _g = g;
var _a = a;
-
+
return function(b) {
_g(_a, b);
};
};
-
+
var createEventHandler = function(handlerCode) {
if (handlerCode) {
return new Function("event", "data", handlerCode);
}
-
+
return null;
};
-
+
//TODO take events just from .java code using EL-expression
var AJAX_EVENTS = (function() {
var serverEventHandler = function(clientHandler, event) {
@@ -431,29 +431,29 @@
clientHandler.call(window, event, data);
}
};
-
+
return {
'begin': null,
'complete': serverEventHandler,
'beforedomupdate': serverEventHandler
}
}());
-
+
richfaces.ajax = function(source, event, options) {
-
+
options = options || {};
var sourceId = (typeof source == 'object' && source.id) ? source.id :
source;
-
+
parameters = options.parameters || {}; // TODO: change "parameters" to
"richfaces.ajax.params"
- parameters.execute = "@component";
+ parameters.execute = "@component";
parameters.render = "@component";
-
+
if (!parameters["org.richfaces.ajax.component"]) {
parameters["org.richfaces.ajax.component"] = sourceId;
}
var eventHandlers;
-
+
for (var eventName in AJAX_EVENTS) {
var handler = createEventHandler(options[eventName]);
@@ -461,7 +461,7 @@
if (serverHandler) {
handler = curry(serverHandler, handler);
}
-
+
if (handler) {
eventHandlers = eventHandlers || {};
eventHandlers[eventName] = handler;
@@ -487,35 +487,35 @@
parameters['onevent'] = eventsAdapter;
parameters['onerror'] = eventsAdapter;
}
-
+
jsf.ajax.request(source, event, parameters);
};
-
+
var RICHFACES_AJAX_STATUS = "richfaces:ajaxStatus";
-
+
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 statusName = getGlobalStatusNameVariable();
var source = data.source;
-
+
var statusApplied = false;
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;
+
+ for (var containerIdx = 0; containerIdx < statusContainers.length &&
!statusApplied;
containerIdx++) {
-
+
var statusContainer = statusContainers[containerIdx];
var statuses = statusContainer.data(statusDataAttribute);
if (statuses) {
@@ -528,7 +528,7 @@
delete statuses[statusId];
}
}
-
+
if (!statusApplied) {
statusContainer.removeData(statusDataAttribute);
}
@@ -548,19 +548,19 @@
success: function(event) { statusAjaxEventHandler(event, 'success'); },
complete: function() { setGlobalStatusNameVariable(null); }
});
-
+
jsf.ajax.addOnEvent(jsfEventsListener);
//TODO blocks default alert error handler
jsf.ajax.addOnError(jsfEventsListener);
}
};
-
+
richfaces.status = function(statusId, options) {
this.statusId = statusId;
this.options = options || {};
this.register();
};
-
+
jQuery.extend(richfaces.status.prototype, (function() {
//TODO - support for parallel requests
@@ -568,7 +568,7 @@
var elt = document.getElementById(this.statusId);
return elt ? jQuery(elt) : null;
};
-
+
var showHide = function(selector) {
var element = getElement.call(this);
if (element) {
@@ -577,17 +577,17 @@
var t = jQuery(this);
t.css('display', t.is(selector) ? '': 'none');
});
-
+
return true;
}
-
+
return false;
};
-
+
return {
register: function() {
initializeStatuses();
-
+
var statusName = this.options.statusName;
var dataStatusAttribute = getStatusDataAttributeName(statusName);
@@ -600,39 +600,39 @@
container = jQuery();
};
}
-
+
var statuses = container.data(dataStatusAttribute);
if (!statuses) {
statuses = {};
container.data(dataStatusAttribute, statuses);
}
-
+
statuses[this.statusId] = this;
},
-
+
start: function() {
if (this.options.onstart) {
this.options.onstart.apply(this, arguments);
}
-
+
return showHide.call(this, '.rich-status-start');
},
-
+
stop: function() {
if (this.options.onstop) {
this.options.onstop.apply(this, arguments);
}
},
-
+
success: function() {
if (this.options.onsuccess) {
this.options.onsuccess.apply(this, arguments);
}
this.stop();
-
+
return showHide.call(this, '.rich-status-stop');
},
-
+
error: function() {
if (this.options.onerror) {
this.options.onerror.apply(this, arguments);
@@ -643,6 +643,6 @@
}
};
}()));
-
+
}(window.RichFaces = {}, jQuery));