You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2009/04/09 17:12:13 UTC

svn commit: r763683 [2/2] - in /myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces: ./ _impl/ _impl/_util/ _impl/core/ _impl/xhrCore/ api/

Added: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_xhrCoreAdapter.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_xhrCoreAdapter.js?rev=763683&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_xhrCoreAdapter.js (added)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_xhrCoreAdapter.js Thu Apr  9 15:12:12 2009
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2009 Ganesh Jung
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Author: Ganesh Jung (latest modification by $Author: werpu $)
+ * Version: $Revision: 1.3 $ $Date: 2009/04/09 13:02:00 $
+ *
+ */
+
+_reserveMyfacesNamespaces();
+
+/**
+ * Constructor
+ */
+myfaces._impl.xhrCore_Ajax = function() {}
+
+/**
+ * [STATIC PROPERTIES]
+ */
+// request, type myfaces._impl.xhrCore_AjaxRequest
+myfaces._impl.xhrCore_Ajax.request = null;
+// Hidden field for ViewState
+myfaces._impl.xhrCore_Ajax.javaxFacesViewState = "javax.faces.ViewState";
+// Hidden field for project-stage. Must be the value from
+// javax.faces.application.Application.getProjectStage()
+myfaces._impl.xhrCore_Ajax.projectState = "myfaces._impl.xhrCore_Ajax.projectStage";
+
+myfaces._impl.xhrCore_Ajax._utils = new myfaces._impl.xhrCore_AjaxUtils();
+
+/**
+ * [STATIC]
+ * Spec. 13.3.1
+ * Collect and encode input elements.
+ * Additinoaly the hidden element javax.faces.ViewState
+ * @param {String} FORM_ELEMENT - Client-Id of Form-Element
+ * @return {String} - Concatenated String of the encoded input elements
+ * 			and javax.faces.ViewState element
+ */
+myfaces._impl.xhrCore_Ajax.prototype.getViewState = function(FORM_ELEMENT) {
+    return utils.processUserEntries(null, FORM_ELEMENT);
+}
+
+
+/**
+ * mapped options already have the exec and view properly in place
+ * j4fry specifics can be found under mappedOptions.myFaces
+ * @param ajaxContext the ajax context which also has to be pushed into the messages and into the response
+
+        var ajaxContext = {};
+        ajaxContext.source = element;
+        ajaxContext.onevent = options.onevent;
+        ajaxContext.onerror = options.onerror;
+
+       action the action to be used in the xhr request
+
+ **/
+
+myfaces._impl.xhrCore_Ajax.prototype._ajaxRequest = function(ELEMENT, ajaxContext, action, viewState, passThroughValues, implementationOptions ) {
+    //TODO ganesh, in theory we just would need a direct mapping of our pass through values
+    //into params we do not need an explict mapping they just have to be encoded before being processed
+    //I have a helper function there in my utils which does the needed processing from array into params
+    //no separate params are needed (check my mini xhir where I am exactly doing this!)
+    //the final params which are passed down are viewstate and the passThroughValues
+
+	if (implementationOptions != null && implementationOptions["errorlevel"] != null)
+        errorlevel = implementationOptions["errorlevel"];
+    else
+        errorlevel = "NONE";
+	if (implementationOptions != null)
+        submit = implementationOptions["submit"];
+    else
+        submit = null;
+
+    myfaces._impl.xhrCore_Ajax.request = new myfaces._impl.xhrCore_AjaxRequest(
+			ELEMENT, "javax.faces.partial.execute=" + passThroughValues["javax.faces.partial.execute"], "javax.faces.partial.render=" + passThroughValues["javax.faces.partial.render"],
+			errorlevel, "javax.faces.partial.source=" + passThroughValues["javax.faces.partial.source"], submit);
+	myfaces._impl.xhrCore_AjaxRequestQueue.queue.queueRequest(myfaces._impl.xhrCore_Ajax.request)
+}
+
+/**
+ *this has to be called by from various stages of the lifecycle
+ *we probably can move this method one level up
+ *
+ *The idea of this method is following:
+ *jsf needs event callback from various stages of the client side lifecycle
+ *either errors or events
+ *
+ *when those events are dispatched in the lifecycle and when the response handling
+ *is called is handled here!
+ */
+myfaces._impl.xhrCore_Ajax._xhrEventDispatcher = function(context, request) {
+
+        var READY_STATE_UNSENT = 0;
+        var READY_STATE_OPENED = 1;
+        var READY_STATE_HEADERS_RECEIVED = 2;
+        var READY_STATE_LOADING = 3;
+        var READY_STATE_DONE = 4;
+
+        
+   
+        var complete = false;
+        /*here we have to do the event mapping back into the ri events*/
+
+        //onEvent and onError are served on the JSF side as well!
+
+
+        switch(request.readyState) {
+            case xhrConst.READY_STATE_OPENED:
+                jsf.ajax.sendEvent(null, context, "begin");
+                break;
+            case READY_STATE_DONE:
+                /**
+                  *here we can do our needed callbacks so
+                  *that the specification is satisfied
+                  **/
+                complete = true;
+
+                var responseStatusCode = request.status;
+
+                if(200 <= responseStatusCode && 300 > responseStatusCode ) {
+                    jsf.ajax.sendEvent(request, context, "complete");
+
+                    jsf.ajax.response(request, context);
+                } else {
+                    jsf.ajax.sendEvent(request, context, "complete");
+                    jsf.ajax.sendError(request, context, "httpError");
+                }
+                break;
+            default:
+                break;
+        }
+        return complete;
+    };
+
+/**
+ * Spec. 13.3.3
+ * Examining the response markup and updating the DOM tree
+ * @param {XmlHttpRequest} request - The Ajax Request
+ * @param {XmlHttpRequest} context - The Ajax context
+ */
+myfaces._impl.xhrCore_Ajax.prototype._ajaxResponse = function(request, context) {
+	if(myfaces._impl.xhrCore_Ajax.request == null)
+		alert("Cannot process ajax response because there's no ajax request.");
+	myfaces._impl.xhrCore_Ajax.request.requestCallback();
+	myfaces._impl.xhrCore_AjaxRequestQueue.queue.processQueue();
+}
+
+/**
+ * [STATIC]
+ * Spec. 13.3.4
+ *
+ * TODO delete this this is templated there is no need to implement it here
+ *
+ */
+myfaces._impl.xhrCore_Ajax.getProjectStage = function() {
+	// TODO: Access hidden field myfaces._impl.xhrCore_Ajax.projectState
+	projectStage = document.getElementById(myfaces._impl.xhrCore_Ajax.projectState);
+	if(projectStage != null) {
+		return projectStage.value();
+	} else {
+		return "Development";
+	}
+}
\ No newline at end of file

Added: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/api/OpenAjax.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/api/OpenAjax.js?rev=763683&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/api/OpenAjax.js (added)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/api/OpenAjax.js Thu Apr  9 15:12:12 2009
@@ -0,0 +1,209 @@
+/*******************************************************************************
+ * OpenAjax.js
+ *
+ * Reference implementation of the OpenAjax Hub, as specified by OpenAjax Alliance.
+ * Specification is under development at:
+ *
+ *   http://www.openajax.org/member/wiki/OpenAjax_Hub_Specification
+ *
+ * Copyright 2006-2008 OpenAjax Alliance
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0 . Unless
+ * required by applicable law or agreed to in writing, software distributed
+ * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ *
+ ******************************************************************************/
+
+// prevent re-definition of the OpenAjax object
+if(!window["OpenAjax"]){
+    OpenAjax = new function(){
+        var t = true;
+        var f = false;
+        var g = window;
+        var libs;
+        var ooh = "org.openajax.hub.";
+
+        var h = {};
+        this.hub = h;
+        h.implementer = "http://openajax.org";
+        h.implVersion = "1.0";
+        h.specVersion = "1.0";
+        h.implExtraData = {};
+        var libs = {};
+        h.libraries = libs;
+
+        h.registerLibrary = function(prefix, nsURL, version, extra){
+            libs[prefix] = {
+                prefix: prefix,
+                namespaceURI: nsURL,
+                version: version,
+                extraData: extra
+            };
+            this.publish(ooh+"registerLibrary", libs[prefix]);
+        }
+        h.unregisterLibrary = function(prefix){
+            this.publish(ooh+"unregisterLibrary", libs[prefix]);
+            delete libs[prefix];
+        }
+
+        h._subscriptions = {
+            c:{},
+            s:[]
+        };
+        h._cleanup = [];
+        h._subIndex = 0;
+        h._pubDepth = 0;
+
+        h.subscribe = function(name, callback, scope, subscriberData, filter)
+        {
+            if(!scope){
+                scope = window;
+            }
+            var handle = name + "." + this._subIndex;
+            var sub = {
+                scope: scope,
+                cb: callback,
+                fcb: filter,
+                data: subscriberData,
+                sid: this._subIndex++,
+                hdl: handle
+            };
+            var path = name.split(".");
+            this._subscribe(this._subscriptions, path, 0, sub);
+            return handle;
+        }
+
+        h.publish = function(name, message)
+        {
+            var path = name.split(".");
+            this._pubDepth++;
+            this._publish(this._subscriptions, path, 0, name, message);
+            this._pubDepth--;
+            if((this._cleanup.length > 0) && (this._pubDepth == 0)) {
+                for(var i = 0; i < this._cleanup.length; i++)
+                    this.unsubscribe(this._cleanup[i].hdl);
+                delete(this._cleanup);
+                this._cleanup = [];
+            }
+        }
+
+        h.unsubscribe = function(sub)
+        {
+            var path = sub.split(".");
+            var sid = path.pop();
+            this._unsubscribe(this._subscriptions, path, 0, sid);
+        }
+
+        h._subscribe = function(tree, path, index, sub)
+        {
+            var token = path[index];
+            if(index == path.length)
+                tree.s.push(sub);
+            else {
+                if(typeof tree.c == "undefined")
+                    tree.c = {};
+                if(typeof tree.c[token] == "undefined") {
+                    tree.c[token] = {
+                        c: {},
+                        s: []
+                    };
+                    this._subscribe(tree.c[token], path, index + 1, sub);
+                }
+                else
+                    this._subscribe( tree.c[token], path, index + 1, sub);
+            }
+        }
+
+        h._publish = function(tree, path, index, name, msg) {
+            if(typeof tree != "undefined") {
+                var node;
+                if(index == path.length) {
+                    node = tree;
+                } else {
+                    this._publish(tree.c[path[index]], path, index + 1, name, msg);
+                    this._publish(tree.c["*"], path, index + 1, name, msg);
+                    node = tree.c["**"];
+                }
+                if(typeof node != "undefined") {
+                    var callbacks = node.s;
+                    var max = callbacks.length;
+                    for(var i = 0; i < max; i++) {
+                        if(callbacks[i].cb) {
+                            var sc = callbacks[i].scope;
+                            var cb = callbacks[i].cb;
+                            var fcb = callbacks[i].fcb;
+                            var d = callbacks[i].data;
+                            if(typeof cb == "string"){
+                                // get a function object
+                                cb = sc[cb];
+                            }
+                            if(typeof fcb == "string"){
+                                // get a function object
+                                fcb = sc[fcb];
+                            }
+                            if((!fcb) ||
+                                (fcb.call(sc, name, msg, d))) {
+                                cb.call(sc, name, msg, d);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        h._unsubscribe = function(tree, path, index, sid) {
+            if(typeof tree != "undefined") {
+                if(index < path.length) {
+                    var childNode = tree.c[path[index]];
+                    this._unsubscribe(childNode, path, index + 1, sid);
+                    if(childNode.s.length == 0) {
+                        for(var x in childNode.c)
+                            return;
+                        delete tree.c[path[index]];
+                    }
+                    return;
+                }
+                else {
+                    var callbacks = tree.s;
+                    var max = callbacks.length;
+                    for(var i = 0; i < max; i++)
+                        if(sid == callbacks[i].sid) {
+                            if(this._pubDepth > 0) {
+                                callbacks[i].cb = null;
+                                this._cleanup.push(callbacks[i]);
+                            }
+                            else
+                                callbacks.splice(i, 1);
+                            return;
+                        }
+                }
+            }
+        }
+        // The following function is provided for automatic testing purposes.
+        // It is not expected to be deployed in run-time OpenAjax Hub implementations.
+        h.reinit = function()
+        {
+            for (var lib in OpenAjax.hub.libraries) {
+                delete OpenAjax.hub.libraries[lib];
+            }
+            OpenAjax.hub.registerLibrary("OpenAjax", "http://openajax.org/hub", "1.0", {});
+
+            delete OpenAjax._subscriptions;
+            OpenAjax._subscriptions = {
+                c:{},
+                s:[]
+            };
+            delete OpenAjax._cleanup;
+            OpenAjax._cleanup = [];
+            OpenAjax._subIndex = 0;
+            OpenAjax._pubDepth = 0;
+        }
+    };
+    // Register the OpenAjax Hub itself as a library.
+    OpenAjax.hub.registerLibrary("OpenAjax", "http://openajax.org/hub", "1.0", {});
+
+}

Added: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/api/jsf.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/api/jsf.js?rev=763683&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/api/jsf.js (added)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/api/jsf.js Thu Apr  9 15:12:12 2009
@@ -0,0 +1,152 @@
+/*
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *  under the License.
+ */
+
+/**
+ *MyFaces core javascripting libraries
+ *
+ *  Those are the central public API functions in the JSF2
+ *  Ajax API! They handle the entire form submit and ajax send
+ *  and resolve cycle!
+ */
+
+/**
+ * reserve the root namespace
+ */
+if ('undefined' != typeof OpenAjax && ('undefined' == typeof jsf || null == typeof jsf)) {
+    OpenAjax.hub.registerLibrary("jsf", "www.sun.com", "1.0", null);
+}
+//just in case openajax has failed (testing environment)
+//under normal circumstances this should not happen
+if ('undefined' == typeof jsf || null == jsf) {
+    jsf = new Object();
+}
+
+/*
+ *just to make sure no questions arise, I simply prefer here a weak
+ *typeless comparison just in case some frameworks try to interfere
+ *by overriding null or fiddeling around with undefined or typeof in some ways
+ *it is safer in this case than the standard way of doing a strong comparison
+ **/
+if ('undefined' == typeof jsf.ajax || null == jsf.ajax) {
+    jsf.ajax = new Object();
+
+    //todo make this overridable by a configuration option
+    /*
+     myfaces.
+     */
+    if ('undefined' != typeof myfaces.config && null != myfaces.config &&
+        'undefined' != typeof myfaces.config.jsfAjaxImpl && null != myfaces.config.jsfAjaxImpl) {
+
+        jsf.ajax._impl = new myfaces.config.jsfAjaxImpl();
+
+    } else {
+
+        jsf.ajax._impl = new myfaces._impl.core._jsfImpl();
+    }
+
+    /**
+     * collect and encode data for a given form element (must be of type form)
+     * find the javax.faces.ViewState element and encode its value as well!
+     * return a concatenated string of the encoded values!
+     *
+     * @throws an exception in case of the given element not being of type form!
+     * https://issues.apache.org/jira/browse/MYFACES-2110
+     */
+    jsf.getViewState = function(formElement) {
+        return jsf.ajax._impl.getViewState(formElement);
+    };
+
+    /**
+     * this function has to send the ajax requests
+     *
+     * following request conditions must be met:
+     * <ul>
+     *  <li> the request must be sent asynchronously! </li>
+     *  <li> the request must be a POST!!! request </li>
+     *  <li> the request url must be the form action attribute </li>
+     *  <li> all requests must be queued with a client side request queue to ensure the request ordering!</li>
+     * </ul>
+     *
+     * @param element: any dom element no matter being it html or jsf, from which the event is emitted
+     * @param event: any javascript event supported by that object
+     * @param options : map of options being pushed into the ajax cycle
+     */
+    jsf.ajax.request = function(/*String|Dom Node*/ element, /*|EVENT|*/ event, /*{|OPTIONS|}*/ options) {
+        return jsf.ajax._impl.request(element, event, options);
+    };
+
+    jsf.ajax.addOnError = function(/*function*/errorListener) {
+        return jsf.ajax._impl.addOnError(errorListener);
+    }
+
+    jsf.ajax.addOnEvent = function(/*function*/eventListener) {
+        return jsf.ajax._impl.addOnError(eventListener);
+    }
+
+    /**
+     * RI compatibility method
+     * TODO make sure this method also occurrs in the specs
+     * otherwise simply pull it
+     */
+    jsf.ajax.sendError = function sendError(/*Object*/request, /*Object*/ context, /*String*/ name, /*String*/ serverErrorName, /*String*/ serverErrorMessage) {
+        jsf.ajax._impl.sendError(request, context, name, serverErrorName, serverErrorMessage);
+    };
+
+    /**
+     * RI compatibility method
+     * TODO make sure this method also occurrs in the specs
+     * otherwise simply pull it
+     */
+    jsf.ajax.sendEvent = function sendEvent(/*Object*/request, /*Object*/ context, /*even name*/ name) {
+        jsf.ajax._impl.sendEvent(request, context, name);
+    }
+
+    /**
+     * processes the ajax response if the ajax request completes successfully
+     * @param request the ajax request!
+     * @param context the ajax context!
+     */
+    jsf.ajax.response = function(/*xhr request object*/request, context) {
+        jsf.ajax._impl.response(request, context);
+    };
+    /**
+     * @return the current project state emitted by the server side method:
+     * javax.faces.application.Application.getProjectStage()
+     */
+    jsf.ajax.getProjectStage = function() {
+        return jsf.ajax._impl.getProjectStage();
+    };
+}
+
+if ('undefined' == typeof jsf.util || null == jsf.util) {
+    jsf.util = new Object();
+
+    /**
+     * varargs function which executes a chain of code (functions or any other code)
+     *
+     * if any of the code returns false, the execution
+     * is terminated prematurely skipping the rest of the code!
+     *
+     * @param {DomNode} source, the callee object
+     * @param {Event} event, the event object of the callee event triggering this function
+     * 
+     */
+    jsf.util.chain = function(source, event) {
+        jsf.ajax._impl.chain.apply(jsf.ajax._impl, arguments);
+    }
+
+}
+
+