Author: nbelaevski
Date: 2008-11-19 11:33:07 -0500 (Wed, 19 Nov 2008)
New Revision: 11240
Added:
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/QueueRegistry.java
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/QueueRenderer.java
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/QueueRendererData.java
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/scripts/
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScriptResourceRenderer.java
trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/
trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/AbstractQueueComponentTest.java
trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/AjaxFormQueuesTest.java
trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/ImplicitQueuesTest.java
trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/QueueDiscoveryTest.java
trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/ScriptTest.java
trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/
trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/ajax-form.xhtml
trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/disabled.xhtml
trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/discovery-base.xhtml
trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/global-both.xhtml
trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/global-form.xhtml
trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/global-view.xhtml
trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/implicit-global-queue.xhtml
trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/legacy.xhtml
trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/simulation.js
Removed:
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScriptResourceRenderer.java
trunk/sandbox/ui/queue/src/main/java/org/richfaces/component/UIQueue.java
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/QueueRegistry.java
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/QueueRenderer.java
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/QueueRendererData.java
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/scripts/
trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/AbstractQueueComponentTest.java
trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/ScriptTest.java
trunk/sandbox/ui/queue/src/test/java/org/richfaces/
trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/simulation.js
trunk/sandbox/ui/queue/src/test/resources/org/richfaces/
Modified:
trunk/sandbox/ui/queue/src/main/config/component/queue.xml
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScript.java
Log:
Queue refactored to org.ajax4jsf.*
Modified: trunk/sandbox/ui/queue/src/main/config/component/queue.xml
===================================================================
--- trunk/sandbox/ui/queue/src/main/config/component/queue.xml 2008-11-19 16:31:41 UTC
(rev 11239)
+++ trunk/sandbox/ui/queue/src/main/config/component/queue.xml 2008-11-19 16:33:07 UTC
(rev 11240)
@@ -2,22 +2,22 @@
<!DOCTYPE components PUBLIC "-//AJAX4JSF//CDK Generator config/EN"
"http://labs.jboss.com/jbossrichfaces/component-config.dtd">
<components>
<component>
- <name>org.richfaces.Queue</name>
- <family>org.richfaces.Queue</family>
- <classname>org.richfaces.component.html.HtmlQueue</classname>
- <superclass>org.richfaces.component.UIQueue</superclass>
+ <name>org.ajax4jsf.Queue</name>
+ <family>org.ajax4jsf.Queue</family>
+ <classname>org.ajax4jsf.component.html.HtmlQueue</classname>
+ <superclass>org.ajax4jsf.component.UIQueue</superclass>
<description>
- <![CDATA[The <rich:queue> tag.]]>
+ <![CDATA[The <a4j:queue> tag.]]>
</description>
<tag generate="true" bodyContent="empty">
<name>queue</name>
- <classname>org.richfaces.taglib.html.jsp.QueueTag</classname>
+ <classname>org.ajax4jsf.taglib.html.jsp.QueueTag</classname>
<superclass>org.ajax4jsf.webapp.taglib.HtmlComponentTagBase</superclass>
<test/>
</tag>
<renderer generate="false">
- <name>org.richfaces.QueueRenderer</name>
- <classname>org.richfaces.renderkit.html.QueueRenderer</classname>
+ <name>org.ajax4jsf.QueueRenderer</name>
+ <classname>org.ajax4jsf.renderkit.html.QueueRenderer</classname>
</renderer>
<!--
<taghandler>
Copied:
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/QueueRegistry.java (from
rev 11187,
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/QueueRegistry.java)
===================================================================
--- trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/QueueRegistry.java
(rev 0)
+++
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/QueueRegistry.java 2008-11-19
16:33:07 UTC (rev 11240)
@@ -0,0 +1,64 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+package org.ajax4jsf.renderkit.html;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.0
+ */
+public class QueueRegistry {
+
+ private static final String REGISTRY_ATTRIBUTE_NAME = QueueRegistry.class.getName();
+
+ public static void registerQueue(FacesContext context, String clientName,
QueueRendererData data) {
+ ExternalContext externalContext = context.getExternalContext();
+ Map<String, Object> requestMap = externalContext.getRequestMap();
+
+ Map<String, QueueRendererData> registryMap = (Map<String,
QueueRendererData>)
+ requestMap.get(REGISTRY_ATTRIBUTE_NAME);
+
+ if (registryMap == null) {
+ registryMap = new LinkedHashMap<String, QueueRendererData>();
+ requestMap.put(REGISTRY_ATTRIBUTE_NAME, registryMap);
+ }
+
+ if (!registryMap.containsKey(clientName)) {
+ registryMap.put(clientName, data);
+ } else {
+ context.getExternalContext().log("Queue with name '" + clientName +
"' has already been registered");
+ }
+ }
+
+ public static Map<String, QueueRendererData> getRegisteredQueues(FacesContext
context) {
+ ExternalContext externalContext = context.getExternalContext();
+ Map<String, Object> requestMap = externalContext.getRequestMap();
+
+ return (Map<String, QueueRendererData>) requestMap.get(REGISTRY_ATTRIBUTE_NAME);
+ }
+}
Property changes on:
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/QueueRegistry.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied:
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/QueueRenderer.java (from
rev 11221,
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/QueueRenderer.java)
===================================================================
--- trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/QueueRenderer.java
(rev 0)
+++
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/QueueRenderer.java 2008-11-19
16:33:07 UTC (rev 11240)
@@ -0,0 +1,182 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.renderkit.html;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.component.UIQueue;
+import org.ajax4jsf.javascript.AjaxScript;
+import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
+import org.ajax4jsf.renderkit.html.scripts.QueueScript;
+import org.ajax4jsf.resource.InternetResource;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.0
+ */
+public class QueueRenderer extends HeaderResourcesRendererBase {
+
+ private static final String QUEUE_ONSUBMIT_ATTRIBUTE = "queueonsubmit";
+
+ private static final String QUEUE_ONBEFOREDOMUPDATE_ATTRIBUTE =
"queueonbeforedomupdate";
+
+ private static final String QUEUE_ONCOMPLETE_ATTRIBUTE = "queueoncomplete";
+
+ private static final String QUEUE_ONERROR_ATTRIBUTE = "queueonerror";
+
+ private static final String[] QUEUE_ATTRIBUTES = new String[] {
+ "enabled",
+ "size",
+ "sizeExceededBehavior"
+ };
+
+ private static final String[] QUEUE_FUNCTION_ATTRIBUTES = new String[] {
+ "onSizeExceeded",
+ "onError",
+ "onExpired"
+ };
+
+ private static final String[] REQUEST_ATTRIBUTES = new String[] {
+ "requestDelay",
+ "timeout",
+ "ignoreDupResponses",
+ "limitToList"
+ };
+
+ private volatile InternetResource[] scripts;
+
+ @Override
+ protected InternetResource[] getScripts() {
+ if (scripts == null) {
+ synchronized (this) {
+ if (scripts == null) {
+ scripts = new InternetResource[] {
+ getResource(AjaxScript.class.getName()),
+ getResource(QueueScript.class.getName())
+ };
+ }
+ }
+ }
+
+ return scripts;
+ }
+
+ @Override
+ protected Class<? extends UIComponent> getComponentClass() {
+ return UIQueue.class;
+ }
+
+ private boolean isNotEmpty(Object object) {
+ if (object == null) {
+ return false;
+ }
+
+ if (object instanceof String) {
+ String s = (String) object;
+ if (s.length() == 0) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private QueueRendererData createRendererData(FacesContext context, UIQueue queue) {
+ Map<String, Object> attributes = queue.getAttributes();
+
+ QueueRendererData data = new QueueRendererData();
+
+ for (String attributeName : QUEUE_ATTRIBUTES) {
+ Object value = attributes.get(attributeName);
+ if (isNotEmpty(value)) {
+ data.addQueueAttribute(attributeName, value);
+ }
+ }
+
+ for (String attributeName : REQUEST_ATTRIBUTES) {
+ Object value = attributes.get(attributeName);
+ if (isNotEmpty(value)) {
+ data.addRequestAttribute(attributeName, value);
+ }
+ }
+
+ for (String attributeName : QUEUE_FUNCTION_ATTRIBUTES) {
+ Object value = attributes.get(attributeName);
+ if (isNotEmpty(value)) {
+ //TODO nick - apply proper functions signature
+ data.addQueueAttribute(attributeName, new
JSFunctionDefinition("event").addToBody(value));
+ }
+ }
+
+ String oncomplete = queue.getOncomplete();
+ if (oncomplete != null) {
+ data.addRequestAttribute(QUEUE_ONCOMPLETE_ATTRIBUTE,
AjaxRendererUtils.buildAjaxOncomplete(oncomplete));
+ }
+
+ String onBeforeDomUpdate = queue.getOnbeforedomupdate();
+ if (onBeforeDomUpdate != null) {
+ data.addRequestAttribute(QUEUE_ONBEFOREDOMUPDATE_ATTRIBUTE,
AjaxRendererUtils.buildAjaxOnBeforeDomUpdate(onBeforeDomUpdate));
+ }
+
+ String onsubmit = queue.getOnsubmit();
+ if (onsubmit != null) {
+ JSFunctionDefinition onsubmitFunction = new
JSFunctionDefinition("request");
+ onsubmitFunction.addToBody(onsubmit);
+
+ data.addRequestAttribute(QUEUE_ONSUBMIT_ATTRIBUTE, onsubmitFunction);
+ }
+
+ String onerror = queue.getOnerror();
+ if (onerror != null) {
+ JSFunctionDefinition onerrorFunction = new JSFunctionDefinition("request",
"status", "message");
+ onerrorFunction.addToBody(onerror);
+
+ data.addRequestAttribute(QUEUE_ONERROR_ATTRIBUTE, onerrorFunction);
+ }
+
+ return data;
+ }
+
+ @Override
+ public void encodeBegin(FacesContext context, UIComponent component)
+ throws IOException {
+ super.encodeBegin(context, component);
+ }
+
+ @Override
+ public void encodeEnd(FacesContext context, UIComponent component)
+ throws IOException {
+ super.encodeEnd(context, component);
+
+ UIQueue queue = (UIQueue) component;
+ if (!queue.isDisabled()) {
+ QueueRegistry.registerQueue(context, queue.getClientName(context),
+ createRendererData(context, queue));
+ }
+ }
+}
Copied:
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/QueueRendererData.java
(from rev 11187,
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/QueueRendererData.java)
===================================================================
---
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/QueueRendererData.java
(rev 0)
+++
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/QueueRendererData.java 2008-11-19
16:33:07 UTC (rev 11240)
@@ -0,0 +1,61 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+package org.ajax4jsf.renderkit.html;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Denis Morozov
+ * @since 3.3.0
+ */
+public class QueueRendererData {
+
+ private Map<String, Object> queueAttributes;
+
+ private Map<String, Object> requestAttributes;
+
+ public void addQueueAttribute(String key, Object value) {
+ if (queueAttributes == null) {
+ queueAttributes = new HashMap<String, Object>();
+ }
+
+ queueAttributes.put(key, value);
+ }
+
+ public void addRequestAttribute(String key, Object value) {
+ if (requestAttributes == null) {
+ requestAttributes = new HashMap<String, Object>();
+ }
+
+ requestAttributes.put(key, value);
+ }
+
+ public Map<String, Object> getQueueAttributes() {
+ return queueAttributes;
+ }
+
+ public Map<String, Object> getRequestAttributes() {
+ return requestAttributes;
+ }
+}
Property changes on:
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/QueueRendererData.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/scripts (from rev
11187, trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/scripts)
Property changes on:
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/scripts
___________________________________________________________________
Name: svn:mergeinfo
+
Modified:
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScript.java
===================================================================
---
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/scripts/QueueScript.java 2008-11-17
11:24:50 UTC (rev 11187)
+++
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScript.java 2008-11-19
16:33:07 UTC (rev 11240)
@@ -19,7 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-package org.richfaces.renderkit.html.scripts;
+package org.ajax4jsf.renderkit.html.scripts;
import org.ajax4jsf.resource.InternetResourceBase;
import org.ajax4jsf.resource.ResourceContext;
Deleted:
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScriptResourceRenderer.java
===================================================================
---
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/scripts/QueueScriptResourceRenderer.java 2008-11-17
11:24:50 UTC (rev 11187)
+++
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScriptResourceRenderer.java 2008-11-19
16:33:07 UTC (rev 11240)
@@ -1,124 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-
-package org.richfaces.renderkit.html.scripts;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-
-import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.javascript.JSObject;
-import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.ajax4jsf.resource.BaseResourceRenderer;
-import org.ajax4jsf.resource.InternetResource;
-import org.richfaces.renderkit.html.QueueRegistry;
-import org.richfaces.renderkit.html.QueueRendererData;
-
-/**
- * @author Nick Belaevski
- * @since 3.3.0
- */
-public class QueueScriptResourceRenderer extends BaseResourceRenderer {
-
- protected void doEncode(InternetResource resource, FacesContext context,
- Object data, Map<String, Object> attributes) throws IOException {
-
- AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
- if (!ajaxContext.isAjaxRequest(context)) {
- Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
-
- String resourceKey = resource.getKey();
- if (requestMap.get(resourceKey) == null) {
- requestMap.put(resourceKey, Boolean.TRUE);
-
- Map<String, QueueRendererData> queues =
QueueRegistry.getRegisteredQueues(context);
-
- if (queues != null && !queues.isEmpty()) {
- super.encode(resource, context, queues, attributes);
- }
- }
- }
- }
-
- @Override
- public void encode(InternetResource resource, FacesContext context,
- Object data, Map<String, Object> attributes) throws IOException {
-
- doEncode(resource, context, data, attributes);
- }
-
- @Override
- public void encode(InternetResource resource, FacesContext context,
- Object data) throws IOException {
-
- doEncode(resource, context, data, Collections.EMPTY_MAP);
- }
-
- @Override
- public void encodeEnd(InternetResource resource,
- FacesContext context, Object data) throws IOException {
-
- ResponseWriter writer = context.getResponseWriter();
- Map<String, QueueRendererData> queues = (Map<String, QueueRendererData>)
data;
-
- for (Entry<String, QueueRendererData> entry : queues.entrySet()) {
- String queueName = entry.getKey();
- QueueRendererData rendererData = entry.getValue();
-
- writer.writeText("A4J.AJAX.EventQueue.addQueue(", null);
- writer.writeText(
- new JSObject("A4J.AJAX.EventQueue",
- queueName,
- rendererData.getQueueAttributes(),
- rendererData.getRequestAttributes()
- ).toScript(), null);
- writer.writeText(");", null);
- }
-
- super.encodeEnd(resource, context, data);
- }
-
- @Override
- protected String[][] getCommonAttrs() {
- return new String[][]{{HTML.TYPE_ATTR, getContentType()}};
- }
-
- @Override
- protected String getHrefAttr() {
- return null;
- }
-
- @Override
- protected String getTag() {
- return HTML.SCRIPT_ELEM;
- }
-
- public String getContentType() {
- return "text/javascript";
- }
-
-}
Copied:
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScriptResourceRenderer.java
(from rev 11192,
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/scripts/QueueScriptResourceRenderer.java)
===================================================================
---
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScriptResourceRenderer.java
(rev 0)
+++
trunk/sandbox/ui/queue/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScriptResourceRenderer.java 2008-11-19
16:33:07 UTC (rev 11240)
@@ -0,0 +1,148 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+package org.ajax4jsf.renderkit.html.scripts;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.component.UIQueue;
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.javascript.JSObject;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.ajax4jsf.renderkit.html.QueueRegistry;
+import org.ajax4jsf.renderkit.html.QueueRendererData;
+import org.ajax4jsf.resource.BaseResourceRenderer;
+import org.ajax4jsf.resource.InternetResource;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.0
+ */
+public class QueueScriptResourceRenderer extends BaseResourceRenderer {
+
+ private void encodeQueue(ResponseWriter writer, String queueName, QueueRendererData
queueData)
+ throws IOException {
+
+ Map<String, Object> queueAttributes = null;
+ Map<String, Object> requestAttributes = null;
+
+ if (queueData != null) {
+ queueAttributes = queueData.getQueueAttributes();
+ requestAttributes = queueData.getRequestAttributes();
+ }
+
+ writer.writeText("A4J.AJAX.EventQueue.addQueue(", null);
+ writer.writeText(
+ new JSObject("A4J.AJAX.EventQueue",
+ queueName,
+ queueAttributes,
+ requestAttributes
+ ).toScript(), null);
+ writer.writeText(");", null);
+ }
+
+ @Override
+ protected void customEncode(InternetResource resource,
+ FacesContext context, Object data) throws IOException {
+ super.customEncode(resource, context, data);
+
+ ResponseWriter writer = context.getResponseWriter();
+
+ Map<String, QueueRendererData> queues =
QueueRegistry.getRegisteredQueues(context);
+
+ ExternalContext externalContext = context.getExternalContext();
+ if
(Boolean.valueOf(externalContext.getInitParameter("org.richfaces.queue.global.enabled")))
{
+ String encodedGlobalQueueName =
externalContext.encodeNamespace(UIQueue.GLOBAL_QUEUE_NAME);
+
+ if (queues == null || !queues.containsKey(encodedGlobalQueueName)) {
+ encodeQueue(writer, encodedGlobalQueueName, null);
+ }
+ }
+
+ if (queues != null && !queues.isEmpty()) {
+ for (Entry<String, QueueRendererData> entry : queues.entrySet()) {
+ encodeQueue(writer, entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
+ protected void doEncode(InternetResource resource, FacesContext context,
+ Object data, Map<String, Object> attributes) throws IOException {
+
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ //TODO nick - what if ajax request?
+ if (!ajaxContext.isAjaxRequest(context)) {
+ ExternalContext externalContext = context.getExternalContext();
+ Map<String, Object> requestMap = externalContext.getRequestMap();
+
+ String resourceKey = resource.getKey();
+ if (requestMap.get(resourceKey) == null) {
+ requestMap.put(resourceKey, Boolean.TRUE);
+
+ super.encode(resource, context, data, attributes);
+ }
+ }
+ }
+
+ @Override
+ public void encode(InternetResource resource, FacesContext context,
+ Object data, Map<String, Object> attributes) throws IOException {
+
+ doEncode(resource, context, data, attributes);
+ }
+
+ @Override
+ public void encode(InternetResource resource, FacesContext context,
+ Object data) throws IOException {
+
+ doEncode(resource, context, data, Collections.EMPTY_MAP);
+ }
+
+ @Override
+ protected String[][] getCommonAttrs() {
+ return new String[][] {
+ {HTML.TYPE_ATTR, getContentType()},
+ };
+ }
+
+ @Override
+ protected String getHrefAttr() {
+ return null;
+ }
+
+ @Override
+ protected String getTag() {
+ return HTML.SCRIPT_ELEM;
+ }
+
+ public String getContentType() {
+ return "text/javascript";
+ }
+
+}
Deleted: trunk/sandbox/ui/queue/src/main/java/org/richfaces/component/UIQueue.java
===================================================================
--- trunk/sandbox/ui/queue/src/main/java/org/richfaces/component/UIQueue.java 2008-11-19
16:31:41 UTC (rev 11239)
+++ trunk/sandbox/ui/queue/src/main/java/org/richfaces/component/UIQueue.java 2008-11-19
16:33:07 UTC (rev 11240)
@@ -1,97 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.component;
-
-import javax.faces.component.NamingContainer;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIComponentBase;
-import javax.faces.component.UIForm;
-import javax.faces.context.FacesContext;
-
-/**
- * @author Nick Belaevski
- * @since 3.3.0
- */
-public abstract class UIQueue extends UIComponentBase {
-
- public static final String COMPONENT_TYPE = "org.richfaces.Queue";
-
- public static final String COMPONENT_FAMILY = "org.richfaces.Queue";
-
- public static final String GLOBAL_QUEUE_NAME = "org.richfaces.queue.global";
-
- public abstract String getName();
- public abstract void setName(String name);
-
- public abstract String getOnsubmit();
- public abstract void setOnsubmit(String onsubmit);
-
- public abstract String getOncomplete();
- public abstract void setOncomplete(String oncomplete);
-
- public abstract String getOnbeforedomupdate();
- public abstract void setOnbeforedomupdate(String onbeforedomupdate);
-
- public abstract String getOnerror();
- public abstract void setOnerror(String onerror);
-
- public abstract boolean isDisabled();
- public abstract void setDisabled(boolean disabled);
-
- @Override
- public String getFamily() {
- return COMPONENT_FAMILY;
- }
-
- private UIComponent findParentForm() {
- UIComponent component = getParent();
- while (component != null && !(component instanceof UIForm)) {
- component = component.getParent();
- }
-
- return component;
- }
-
- public String getClientName(FacesContext context) {
- UIComponent form = findParentForm();
- String name = getName();
- String clientName;
-
- if (form != null) {
- String formClientId = form.getClientId(context);
-
- if (name != null && name.length() != 0) {
- clientName = formClientId + NamingContainer.SEPARATOR_CHAR + name;
- } else {
- clientName = formClientId;
- }
- } else {
- if (name == null || name.length() == 0) {
- name = UIQueue.GLOBAL_QUEUE_NAME;
- }
-
- clientName = context.getExternalContext().encodeNamespace(name);
- }
-
- return clientName;
- }
-}
Deleted:
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/QueueRegistry.java
===================================================================
---
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/QueueRegistry.java 2008-11-19
16:31:41 UTC (rev 11239)
+++
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/QueueRegistry.java 2008-11-19
16:33:07 UTC (rev 11240)
@@ -1,64 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-
-package org.richfaces.renderkit.html;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-
-/**
- * @author Nick Belaevski
- * @since 3.3.0
- */
-public class QueueRegistry {
-
- private static final String REGISTRY_ATTRIBUTE_NAME = QueueRegistry.class.getName();
-
- public static void registerQueue(FacesContext context, String clientName,
QueueRendererData data) {
- ExternalContext externalContext = context.getExternalContext();
- Map<String, Object> requestMap = externalContext.getRequestMap();
-
- Map<String, QueueRendererData> registryMap = (Map<String,
QueueRendererData>)
- requestMap.get(REGISTRY_ATTRIBUTE_NAME);
-
- if (registryMap == null) {
- registryMap = new LinkedHashMap<String, QueueRendererData>();
- requestMap.put(REGISTRY_ATTRIBUTE_NAME, registryMap);
- }
-
- if (!registryMap.containsKey(clientName)) {
- registryMap.put(clientName, data);
- } else {
- context.getExternalContext().log("Queue with name '" + clientName +
"' has already been registered");
- }
- }
-
- public static Map<String, QueueRendererData> getRegisteredQueues(FacesContext
context) {
- ExternalContext externalContext = context.getExternalContext();
- Map<String, Object> requestMap = externalContext.getRequestMap();
-
- return (Map<String, QueueRendererData>) requestMap.get(REGISTRY_ATTRIBUTE_NAME);
- }
-}
Deleted:
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/QueueRenderer.java
===================================================================
---
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/QueueRenderer.java 2008-11-19
16:31:41 UTC (rev 11239)
+++
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/QueueRenderer.java 2008-11-19
16:33:07 UTC (rev 11240)
@@ -1,182 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.renderkit.html;
-
-import java.io.IOException;
-import java.util.Map;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.javascript.AjaxScript;
-import org.ajax4jsf.javascript.JSFunctionDefinition;
-import org.ajax4jsf.renderkit.AjaxRendererUtils;
-import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
-import org.ajax4jsf.resource.InternetResource;
-import org.richfaces.component.UIQueue;
-import org.richfaces.renderkit.html.scripts.QueueScript;
-
-/**
- * @author Nick Belaevski
- * @since 3.3.0
- */
-public class QueueRenderer extends HeaderResourcesRendererBase {
-
- private static final String QUEUE_ONSUBMIT_ATTRIBUTE = "queueonsubmit";
-
- private static final String QUEUE_ONBEFOREDOMUPDATE_ATTRIBUTE =
"queueonbeforedomupdate";
-
- private static final String QUEUE_ONCOMPLETE_ATTRIBUTE = "queueoncomplete";
-
- private static final String QUEUE_ONERROR_ATTRIBUTE = "queueonerror";
-
- private static final String[] QUEUE_ATTRIBUTES = new String[] {
- "enabled",
- "size",
- "sizeExceededBehavior"
- };
-
- private static final String[] QUEUE_FUNCTION_ATTRIBUTES = new String[] {
- "onSizeExceeded",
- "onError",
- "onExpired"
- };
-
- private static final String[] REQUEST_ATTRIBUTES = new String[] {
- "requestDelay",
- "timeout",
- "ignoreDupResponses",
- "limitToList"
- };
-
- private volatile InternetResource[] scripts;
-
- @Override
- protected InternetResource[] getScripts() {
- if (scripts == null) {
- synchronized (this) {
- if (scripts == null) {
- scripts = new InternetResource[] {
- getResource(AjaxScript.class.getName()),
- getResource(QueueScript.class.getName())
- };
- }
- }
- }
-
- return scripts;
- }
-
- @Override
- protected Class<? extends UIComponent> getComponentClass() {
- return UIQueue.class;
- }
-
- private boolean isNotEmpty(Object object) {
- if (object == null) {
- return false;
- }
-
- if (object instanceof String) {
- String s = (String) object;
- if (s.length() == 0) {
- return false;
- }
- }
-
- return true;
- }
-
- private QueueRendererData createRendererData(FacesContext context, UIQueue queue) {
- Map<String, Object> attributes = queue.getAttributes();
-
- QueueRendererData data = new QueueRendererData();
-
- for (String attributeName : QUEUE_ATTRIBUTES) {
- Object value = attributes.get(attributeName);
- if (isNotEmpty(value)) {
- data.addQueueAttribute(attributeName, value);
- }
- }
-
- for (String attributeName : REQUEST_ATTRIBUTES) {
- Object value = attributes.get(attributeName);
- if (isNotEmpty(value)) {
- data.addRequestAttribute(attributeName, value);
- }
- }
-
- for (String attributeName : QUEUE_FUNCTION_ATTRIBUTES) {
- Object value = attributes.get(attributeName);
- if (isNotEmpty(value)) {
- //TODO nick - apply proper functions signature
- data.addQueueAttribute(attributeName, new
JSFunctionDefinition("event").addToBody(value));
- }
- }
-
- String oncomplete = queue.getOncomplete();
- if (oncomplete != null) {
- data.addRequestAttribute(QUEUE_ONCOMPLETE_ATTRIBUTE,
AjaxRendererUtils.buildAjaxOncomplete(oncomplete));
- }
-
- String onBeforeDomUpdate = queue.getOnbeforedomupdate();
- if (onBeforeDomUpdate != null) {
- data.addRequestAttribute(QUEUE_ONBEFOREDOMUPDATE_ATTRIBUTE,
AjaxRendererUtils.buildAjaxOnBeforeDomUpdate(onBeforeDomUpdate));
- }
-
- String onsubmit = queue.getOnsubmit();
- if (onsubmit != null) {
- JSFunctionDefinition onsubmitFunction = new
JSFunctionDefinition("request");
- onsubmitFunction.addToBody(onsubmit);
-
- data.addRequestAttribute(QUEUE_ONSUBMIT_ATTRIBUTE, onsubmitFunction);
- }
-
- String onerror = queue.getOnerror();
- if (onerror != null) {
- JSFunctionDefinition onerrorFunction = new JSFunctionDefinition("request",
"status", "message");
- onerrorFunction.addToBody(onerror);
-
- data.addRequestAttribute(QUEUE_ONERROR_ATTRIBUTE, onerrorFunction);
- }
-
- return data;
- }
-
- @Override
- public void encodeBegin(FacesContext context, UIComponent component)
- throws IOException {
- super.encodeBegin(context, component);
- }
-
- @Override
- public void encodeEnd(FacesContext context, UIComponent component)
- throws IOException {
- super.encodeEnd(context, component);
-
- UIQueue queue = (UIQueue) component;
- if (!queue.isDisabled()) {
- QueueRegistry.registerQueue(context, queue.getClientName(context),
- createRendererData(context, queue));
- }
- }
-}
Deleted:
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/QueueRendererData.java
===================================================================
---
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/QueueRendererData.java 2008-11-19
16:31:41 UTC (rev 11239)
+++
trunk/sandbox/ui/queue/src/main/java/org/richfaces/renderkit/html/QueueRendererData.java 2008-11-19
16:33:07 UTC (rev 11240)
@@ -1,61 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-
-package org.richfaces.renderkit.html;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author Denis Morozov
- * @since 3.3.0
- */
-public class QueueRendererData {
-
- private Map<String, Object> queueAttributes;
-
- private Map<String, Object> requestAttributes;
-
- public void addQueueAttribute(String key, Object value) {
- if (queueAttributes == null) {
- queueAttributes = new HashMap<String, Object>();
- }
-
- queueAttributes.put(key, value);
- }
-
- public void addRequestAttribute(String key, Object value) {
- if (requestAttributes == null) {
- requestAttributes = new HashMap<String, Object>();
- }
-
- requestAttributes.put(key, value);
- }
-
- public Map<String, Object> getQueueAttributes() {
- return queueAttributes;
- }
-
- public Map<String, Object> getRequestAttributes() {
- return requestAttributes;
- }
-}
Copied: trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf (from rev 11187,
trunk/sandbox/ui/queue/src/test/java/org/richfaces)
Property changes on: trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted:
trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/AbstractQueueComponentTest.java
===================================================================
---
trunk/sandbox/ui/queue/src/test/java/org/richfaces/AbstractQueueComponentTest.java 2008-11-17
11:24:50 UTC (rev 11187)
+++
trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/AbstractQueueComponentTest.java 2008-11-19
16:33:07 UTC (rev 11240)
@@ -1,369 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-
-package org.richfaces;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIComponentBase;
-import javax.faces.component.UIForm;
-import javax.faces.component.UIViewRoot;
-import javax.faces.component.html.HtmlOutputText;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.render.Renderer;
-
-import org.ajax4jsf.component.UIAjaxCommandButton;
-import org.ajax4jsf.component.UIResource;
-import org.ajax4jsf.component.html.HtmlLoadScript;
-import org.ajax4jsf.javascript.JSFunction;
-import org.ajax4jsf.javascript.JSReference;
-import org.ajax4jsf.renderkit.AjaxRendererUtils;
-import org.ajax4jsf.renderkit.UserResourceRenderer2;
-import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
-import org.mozilla.javascript.NativeArray;
-import org.mozilla.javascript.NativeObject;
-
-import com.gargoylesoftware.htmlunit.AlertHandler;
-import com.gargoylesoftware.htmlunit.Page;
-import com.gargoylesoftware.htmlunit.ScriptResult;
-import com.gargoylesoftware.htmlunit.WebClient;
-import com.gargoylesoftware.htmlunit.html.HtmlPage;
-import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
-import com.sun.facelets.Facelet;
-import com.sun.facelets.FaceletFactory;
-import com.sun.facelets.compiler.SAXCompiler;
-import com.sun.facelets.impl.DefaultFaceletFactory;
-import com.sun.facelets.impl.ResourceResolver;
-
-/**
- * @author Nick Belaevski
- * @since 3.3.0
- */
-public abstract class AbstractQueueComponentTest extends AbstractAjax4JsfTestCase
implements ResourceResolver {
-
- private static final String COMPONENT_TYPE =
AjaxSubmitFunctionComponent.class.getName();
-
- public final static class AjaxSubmitFunctionComponent extends UIComponentBase {
-
- @Override
- public String getRendererType() {
- return COMPONENT_TYPE;
- }
-
- @Override
- public String getFamily() {
- return COMPONENT_TYPE;
- }
-
- }
-
- private final static class AjaxSubmitFunctionResourceRenderer extends
- Renderer implements UserResourceRenderer2 {
-
- public void encodeToHead(FacesContext facesContext, UIComponent component)
- throws IOException {
- JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(component,
facesContext);
- Map<String, Object> options = AjaxRendererUtils.buildEventOptions(facesContext,
component);
- options.put("requestDelay", new
JSReference("parameters.requestDelay"));
- options.put("requestId", new JSReference("parameters.requestId ||
'" + component.getClientId(facesContext) + "'"));
- options.put("data", new JSReference("data"));
- options.put("requestTime", new JSReference("parameters.requestTime ||
1000"));
- options.put("timeout", new JSReference("parameters.timeout"));
- options.put("eventsQueue", new JSReference("parameters.eventsQueue ||
'testQueue'"));
-
- ajaxFunction.addParameter(options);
-
- ResponseWriter responseWriter = facesContext.getResponseWriter();
- responseWriter.startElement(HTML.SCRIPT_ELEM, component);
- responseWriter.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
- responseWriter.writeText("var ajaxSubmit = function(data, parameters) {" +
ajaxFunction.toScript() + "};", null);
- responseWriter.endElement(HTML.SCRIPT_ELEM);
- }
-
- @Override
- public void encodeBegin(FacesContext context, UIComponent component)
- throws IOException {
- }
-
- @Override
- public void encodeEnd(FacesContext context, UIComponent component)
- throws IOException {
- ResponseWriter responseWriter = context.getResponseWriter();
- responseWriter.startElement(HTML.SPAN_ELEM, component);
- responseWriter.writeAttribute(HTML.id_ATTRIBUTE, component.getClientId(context),
null);
- responseWriter.writeText("hi", null);
- responseWriter.endElement(HTML.SPAN_ELEM);
- }
- }
-
- public AbstractQueueComponentTest(String name) {
- super(name);
- }
-
- public URL resolveUrl(String path) {
- return
Thread.currentThread().getContextClassLoader().getResource("org/richfaces" +
path);
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
-
- UIViewRoot viewRoot = facesContext.getViewRoot();
- UIResource resource;
-
- UIComponent form = application.createComponent(UIForm.COMPONENT_TYPE);
- viewRoot.getChildren().add(form);
- final UIComponent commandButton =
application.createComponent(UIAjaxCommandButton.COMPONENT_TYPE);
- form.getChildren().add(commandButton);
-
- facesContext.getRenderKit().addRenderer(COMPONENT_TYPE, COMPONENT_TYPE, new
AjaxSubmitFunctionResourceRenderer());
- form.getChildren().add(new AjaxSubmitFunctionComponent());
-
- resource = (UIResource) application.createComponent(HtmlLoadScript.COMPONENT_TYPE);
- resource.setSrc("resource:///org/richfaces/simulation.js");
- viewRoot.getChildren().add(resource);
-
- }
-
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- }
-
- private List<ScriptCommand> scriptCommands = new
ArrayList<ScriptCommand>();
-
- private abstract interface ScriptCommand {
- public void append(StringBuilder builder);
- }
-
- private static final class DelayCommand implements ScriptCommand {
- private int delayValue;
-
- public DelayCommand(int value) {
- super();
- this.delayValue = value;
- }
-
- public void append(StringBuilder builder) {
- builder.append("wait(" + delayValue + ");");
- }
- }
-
- private static final class AjaxCommand implements ScriptCommand {
- private String data;
- private String parameters;
-
- public AjaxCommand(String data, String parameters) {
- super();
- this.data = data;
- this.parameters = parameters;
- }
-
- public void append(StringBuilder builder) {
- builder.append("ajax('" + data + "', " + parameters +
");");
- }
- }
-
- protected static final class TestsResult {
- private List<RequestData> dataList = new ArrayList<RequestData>();
-
- private Number currentTime;
-
- public void addData(RequestData data) {
- this.dataList.add(data);
- }
-
- public List<RequestData> getDataList() {
- return dataList;
- }
-
- public void setCurrentTime(Number number) {
- this.currentTime = number;
- }
-
- public Number getCurrentTime() {
- return currentTime;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
-
- builder.append("[\n");
- for (RequestData data : dataList) {
- builder.append(" ");
- builder.append(data);
- builder.append("\n");
- }
- builder.append("]\n");
- builder.append("Current time: " + this.currentTime);
-
- return builder.toString();
- }
- }
-
- protected static final class RequestData {
- private boolean timedOut;
-
- private Number startTime;
-
- private Number endTime;
-
- private String data;
-
- public RequestData(String data, Number startTime, Number endTime,
- boolean timedOut) {
- super();
- this.data = data;
- this.startTime = startTime;
- this.endTime = endTime;
- this.timedOut = timedOut;
- }
-
- public boolean isTimedOut() {
- return timedOut;
- }
-
- public Number getStartTime() {
- return startTime;
- }
-
- public Number getEndTime() {
- return endTime;
- }
-
- public String getData() {
- return data;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
-
- builder.append("data: ");
- builder.append(data);
- builder.append(", ");
-
- builder.append("startTime: ");
- builder.append(startTime);
- builder.append(", ");
-
- builder.append("endTime: ");
- builder.append(endTime);
- builder.append(", ");
-
- if (isTimedOut()) {
- builder.append("timeout: ");
- builder.append(true);
- }
-
- return builder.toString();
- }
- };
-
- protected void ajax(String data, String parameters) {
- scriptCommands.add(new AjaxCommand(data, parameters));
- }
-
- protected void delay(int delayValue) {
- scriptCommands.add(new DelayCommand(delayValue));
- }
-
- protected void buildView(String viewId) throws IOException {
- com.sun.facelets.compiler.Compiler c = new SAXCompiler();
- FaceletFactory factory = new DefaultFaceletFactory(c, this);
- FaceletFactory.setInstance(factory);
-
- FaceletFactory f = FaceletFactory.getInstance();
- Facelet at = f.getFacelet(viewId);
-
- UIViewRoot root = facesContext.getViewRoot();
- root.setViewId(viewId);
- at.apply(facesContext, root);
- }
-
- @Override
- protected HtmlPage renderView() throws Exception {
- StringBuilder builder = new StringBuilder("<script
type='text/javascript'>do { with (simulationContext) {");
- for (ScriptCommand command : scriptCommands) {
- command.append(builder);
- }
- builder.append("}; Timer.execute(); } while
(!Timer.isEmpty());</script>");
-
- HtmlOutputText text = new HtmlOutputText();
- text.setEscape(false);
- text.setValue(builder.toString());
-
- List<UIComponent> childList = facesContext.getViewRoot().getChildren();
- childList.add(childList.size(), text);
-
- return super.renderView();
- }
-
- protected TestsResult getTestsResult(HtmlPage page) {
- TestsResult result = new TestsResult();
-
- ScriptResult scriptResult =
page.executeJavaScript("window.simulationContext.results");
- NativeArray array = (NativeArray) scriptResult.getJavaScriptResult();
-
- for (int i = 0; i < array.getLength(); i++) {
- NativeObject object = (NativeObject) array.get(i, array);
-
- String data = (String) object.get("data", object);
- Number startTime = (Number) object.get("startTime", object);
- Number endTime = (Number) object.get("endTime", object);
-
- Object timedOut = object.get("timedOut", object);
- boolean timedOutBoolean = timedOut instanceof Boolean && (Boolean) timedOut;
-
- result.addData(new RequestData(data, startTime, endTime, timedOutBoolean));
- }
-
- scriptResult = page.executeJavaScript("Timer.currentTime");
- result.setCurrentTime((Number) scriptResult.getJavaScriptResult());
-
- return result;
- }
-
- @Override
- protected WebClient createWebClient() {
- WebClient webClient = super.createWebClient();
- webClient.setJavaScriptEngine(new JavaScriptEngine(webClient));
- webClient.setAlertHandler(new AlertHandler() {
-
- public void handleAlert(Page page, String message) {
- fail(message);
- }
-
- });
-
- return webClient;
- }
-
-}
Copied: trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/AbstractQueueComponentTest.java
(from rev 11238,
trunk/sandbox/ui/queue/src/test/java/org/richfaces/AbstractQueueComponentTest.java)
===================================================================
--- trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/AbstractQueueComponentTest.java
(rev 0)
+++
trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/AbstractQueueComponentTest.java 2008-11-19
16:33:07 UTC (rev 11240)
@@ -0,0 +1,478 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+package org.ajax4jsf;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.component.UIForm;
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.html.HtmlOutputText;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.Renderer;
+
+import org.ajax4jsf.component.UIAjaxCommandButton;
+import org.ajax4jsf.component.UIResource;
+import org.ajax4jsf.component.html.HtmlLoadScript;
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSReference;
+import org.ajax4jsf.javascript.ScriptUtils;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.renderkit.UserResourceRenderer2;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.mozilla.javascript.NativeArray;
+import org.mozilla.javascript.NativeObject;
+import org.mozilla.javascript.Undefined;
+
+import com.gargoylesoftware.htmlunit.AlertHandler;
+import com.gargoylesoftware.htmlunit.Page;
+import com.gargoylesoftware.htmlunit.ScriptPreProcessor;
+import com.gargoylesoftware.htmlunit.ScriptResult;
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
+import com.sun.facelets.Facelet;
+import com.sun.facelets.FaceletFactory;
+import com.sun.facelets.compiler.Compiler;
+import com.sun.facelets.compiler.SAXCompiler;
+import com.sun.facelets.impl.DefaultFaceletFactory;
+import com.sun.facelets.impl.ResourceResolver;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.0
+ */
+public abstract class AbstractQueueComponentTest extends AbstractAjax4JsfTestCase {
+
+ private static final String COMPONENT_TYPE =
AjaxSubmitFunctionComponent.class.getName();
+
+ private static final String AJAX_SUBMIT = "ajaxSubmit";
+
+ protected HtmlPage page;
+
+ public final static class AjaxSubmitFunctionComponent extends UIComponentBase {
+
+ @Override
+ public String getRendererType() {
+ return COMPONENT_TYPE;
+ }
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_TYPE;
+ }
+
+ }
+
+ private final static class AjaxSubmitFunctionResourceRenderer extends
+ Renderer implements UserResourceRenderer2 {
+
+ public void encodeToHead(FacesContext facesContext, UIComponent component)
+ throws IOException {
+ JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(component,
facesContext);
+ Map<String, Object> options = AjaxRendererUtils.buildEventOptions(facesContext,
component);
+ options.put("requestDelay", new
JSReference("parameters.requestDelay"));
+ options.put("requestId", new JSReference("parameters.requestId ||
'" + component.getClientId(facesContext) + "'"));
+ options.put("data", new JSReference("data"));
+ options.put("requestTime", new JSReference("parameters.requestTime ||
1000"));
+ options.put("timeout", new JSReference("parameters.timeout"));
+ options.put("eventsQueue", new
JSReference("parameters.eventsQueue"));
+ options.put("implicitEventsQueue", new
JSReference("parameters.implicitEventsQueue"));
+
+ ajaxFunction.addParameter(options);
+
+ ResponseWriter responseWriter = facesContext.getResponseWriter();
+ responseWriter.startElement(HTML.SCRIPT_ELEM, component);
+ responseWriter.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
+ responseWriter.writeText("var " + AJAX_SUBMIT + " = function(data,
parameters) {" + ajaxFunction.toScript() + "};", null);
+ responseWriter.endElement(HTML.SCRIPT_ELEM);
+ }
+
+ }
+
+ public AbstractQueueComponentTest(String name) {
+ super(name);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ UIViewRoot viewRoot = facesContext.getViewRoot();
+ UIResource resource;
+
+ UIComponent form = application.createComponent(UIForm.COMPONENT_TYPE);
+ viewRoot.getChildren().add(form);
+ final UIComponent commandButton =
application.createComponent(UIAjaxCommandButton.COMPONENT_TYPE);
+ form.getChildren().add(commandButton);
+
+ facesContext.getRenderKit().addRenderer(COMPONENT_TYPE, COMPONENT_TYPE, new
AjaxSubmitFunctionResourceRenderer());
+ form.getChildren().add(new AjaxSubmitFunctionComponent());
+
+ resource = (UIResource) application.createComponent(HtmlLoadScript.COMPONENT_TYPE);
+ resource.setSrc("resource:///org/ajax4jsf/simulation.js");
+ viewRoot.getChildren().add(resource);
+
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ this.page = null;
+ super.tearDown();
+ }
+
+ protected static final class ParametersBuilder {
+ private Map<String, Object> parameters;
+
+ private ParametersBuilder() {
+ this.parameters = new HashMap<String, Object>();
+ }
+
+ private ParametersBuilder(Map<String, Object> parameters) {
+ this.parameters = new HashMap<String, Object>(parameters);
+ }
+
+ private ParametersBuilder put(String key, Object value) {
+ this.parameters.put(key, value);
+ return this;
+ }
+
+ private String getParamatersString() {
+ return ScriptUtils.toScript(parameters);
+ }
+
+ public ParametersBuilder requestDelay(double value) {
+ return new ParametersBuilder(this.parameters).put("requestDelay", value);
+ }
+ public ParametersBuilder requestId(Object id) {
+ return new ParametersBuilder(this.parameters).put("requestId", id);
+ }
+ public ParametersBuilder requestTime(double value) {
+ return new ParametersBuilder(this.parameters).put("requestTime", value);
+ }
+ public ParametersBuilder timeout(double value) {
+ return new ParametersBuilder(this.parameters).put("timeout", value);
+ }
+ public ParametersBuilder eventsQueue(String name) {
+ return new ParametersBuilder(this.parameters).put("eventsQueue", name);
+ }
+ public ParametersBuilder implicitEventsQueue(String name) {
+ return new ParametersBuilder(this.parameters).put("implicitEventsQueue",
name);
+ }
+ }
+
+ protected ParametersBuilder createAjaxParameters() {
+ return new ParametersBuilder();
+ }
+
+ protected static final class TestsResult {
+ private List<RequestData> dataList = new ArrayList<RequestData>();
+
+ private double currentTime;
+
+ public void addData(RequestData data) {
+ this.dataList.add(data);
+ }
+
+ public List<RequestData> getDataList() {
+ return dataList;
+ }
+
+ public void setCurrentTime(double number) {
+ this.currentTime = number;
+ }
+
+ public double getCurrentTime() {
+ return currentTime;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+
+ builder.append("[\n");
+ for (RequestData data : dataList) {
+ builder.append(" ");
+ builder.append(data);
+ builder.append("\n");
+ }
+ builder.append("]\n");
+ builder.append("Current time: " + this.currentTime);
+
+ return builder.toString();
+ }
+ }
+
+ protected static final class RequestData {
+ private boolean aborted;
+
+ private double startTime;
+
+ private double endTime;
+
+ private String data;
+
+ public RequestData(String data, double startTime, double endTime,
+ boolean aborted) {
+ super();
+ this.data = data;
+ this.startTime = startTime;
+ this.endTime = endTime;
+ this.aborted = aborted;
+ }
+
+ public boolean isAborted() {
+ return aborted;
+ }
+
+ public double getStartTime() {
+ return startTime;
+ }
+
+ public double getEndTime() {
+ return endTime;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+
+ builder.append("data: ");
+ builder.append(data);
+ builder.append(", ");
+
+ builder.append("startTime: ");
+ builder.append(startTime);
+ builder.append(", ");
+
+ builder.append("endTime: ");
+ builder.append(endTime);
+
+ if (isAborted()) {
+ builder.append(", aborted: ");
+ builder.append(true);
+ }
+
+ return builder.toString();
+ }
+ };
+
+ protected void assertRequestData(RequestData requestData, String data,
+ double startTime, double endTime, boolean aborted) {
+
+ assertEquals("Data check failed for " + requestData, data,
requestData.getData());
+ assertEquals("Start time check failed for " + requestData, startTime,
requestData.getStartTime());
+ assertEquals("End time check failed for " + requestData, endTime,
requestData.getEndTime());
+ assertEquals("Aborted check failed for " + requestData, aborted,
requestData.isAborted());
+
+ }
+
+ protected void ajax(String data, String parameters) {
+ page.executeJavaScript("simulationContext.ajax('" + data + "',
" + parameters + ");");
+ }
+
+ protected void ajax(String data, ParametersBuilder builder) {
+ ajax(data, builder.getParamatersString());
+ }
+
+ protected void executeAfterDelay(String expression) {
+ page.executeJavaScript("simulationContext.executeAfterDelay(function(){" +
expression + "});");
+ }
+
+ protected void delay(int delayValue) {
+ page.executeJavaScript("simulationContext.wait(" + delayValue +
");");
+ }
+
+ protected String getRootContextPath() {
+ return this.getClass().getPackage().getName().replace('.', '/');
+ }
+
+ protected ResourceResolver createResourceResolver() {
+ return new ResourceResolver() {
+
+ public URL resolveUrl(String path) {
+ return
Thread.currentThread().getContextClassLoader().getResource(getRootContextPath() + path);
+ }
+
+ };
+ }
+
+ private static final Compiler compiler = new SAXCompiler();
+
+ protected void buildView(String viewId) throws IOException {
+ FaceletFactory factory = new DefaultFaceletFactory(compiler,
createResourceResolver());
+ FaceletFactory.setInstance(factory);
+
+ FaceletFactory f = FaceletFactory.getInstance();
+ Facelet at = f.getFacelet(viewId);
+
+ UIViewRoot root = facesContext.getViewRoot();
+ root.setViewId(viewId);
+ at.apply(facesContext, root);
+ }
+
+ protected void preRenderView() throws Exception {
+ StringBuilder builder = new StringBuilder("<script
type='text/javascript'>");
+ builder.append("window.simulationContext = new SimulationContext(");
+ builder.append(AJAX_SUBMIT);
+ builder.append(");</script>");
+
+ HtmlOutputText text = new HtmlOutputText();
+ text.setEscape(false);
+ text.setValue(builder.toString());
+
+ List<UIComponent> childList = facesContext.getViewRoot().getChildren();
+ childList.add(childList.size(), text);
+ }
+
+ protected HtmlPage renderView(String viewId) throws Exception {
+ buildView(viewId);
+ preRenderView();
+ this.page = super.renderView();
+
+ return this.page;
+ }
+
+ @Override
+ protected HtmlPage renderView() throws Exception {
+ preRenderView();
+ this.page = super.renderView();
+
+ return this.page;
+ }
+
+ protected Object executeJavaScript(String expression) {
+ return page.executeJavaScript(expression).getJavaScriptResult();
+ }
+
+ protected void executeTimer() {
+ page.executeJavaScript("Timer.execute();");
+ }
+
+ protected TestsResult getTestsResult() {
+ TestsResult result = new TestsResult();
+
+ executeTimer();
+ ScriptResult scriptResult =
page.executeJavaScript("window.simulationContext.results");
+ NativeArray array = (NativeArray) scriptResult.getJavaScriptResult();
+
+ for (int i = 0; i < array.getLength(); i++) {
+ NativeObject object = (NativeObject) array.get(i, array);
+
+ String data = null;
+
+ Object dataObject = object.get("data", object);
+ if (!(dataObject instanceof Undefined)) {
+ data = (String) dataObject;
+ }
+
+ Double startTime = (Double) object.get("startTime", object);
+ Double endTime = (Double) object.get("endTime", object);
+
+ Object aborted = object.get("aborted", object);
+ boolean abortedBoolean = aborted instanceof Boolean && (Boolean) aborted;
+
+ result.addData(new RequestData(data, startTime, endTime, abortedBoolean));
+ }
+
+ scriptResult = page.executeJavaScript("Timer.currentTime");
+ result.setCurrentTime((Double) scriptResult.getJavaScriptResult());
+
+ return result;
+ }
+
+ @Override
+ protected void setupWebClient() {
+ super.setupWebClient();
+ webClient.setJavaScriptEngine(new JavaScriptEngine(webClient));
+ webClient.setScriptPreProcessor(new UnescapingScriptPreprocessor());
+ webClient.setThrowExceptionOnScriptError(true);
+ webClient.setAlertHandler(new AlertHandler() {
+
+ public void handleAlert(Page page, String message) {
+ fail(message);
+ }
+
+ });
+ }
+}
+
+class UnescapingScriptPreprocessor implements ScriptPreProcessor {
+
+ private static final Map<String, String> ENTITIES_MAP = new HashMap<String,
String>();
+
+ static {
+ ENTITIES_MAP.put("'", "\"");
+ ENTITIES_MAP.put(""", "'");
+ }
+
+ private static final Pattern ENTITIES_PATTERN;
+
+ static {
+ StringBuilder sb = new StringBuilder();
+
+ for (String entity : ENTITIES_MAP.keySet()) {
+ if (sb.length() != 0) {
+ sb.append('|');
+ }
+
+ sb.append(Pattern.quote(entity));
+ }
+
+ ENTITIES_PATTERN = Pattern.compile("(" + sb.toString() + ")");
+ }
+
+ public String preProcess(HtmlPage htmlPage, String sourceCode,
+ String sourceName, HtmlElement htmlElement) {
+
+ if (sourceName != null && !sourceName.startsWith("http:/")) {
+ Matcher m = ENTITIES_PATTERN.matcher(sourceCode);
+ StringBuffer sb = new StringBuffer();
+ while (m.find()) {
+ String entity = m.group(1);
+ m.appendReplacement(sb, ENTITIES_MAP.get(entity));
+ }
+
+ m.appendTail(sb);
+
+ return sb.toString();
+ } else {
+ return sourceCode;
+ }
+
+ }
+}
Copied: trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/AjaxFormQueuesTest.java (from
rev 11238, trunk/sandbox/ui/queue/src/test/java/org/richfaces/AjaxFormQueuesTest.java)
===================================================================
--- trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/AjaxFormQueuesTest.java
(rev 0)
+++ trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/AjaxFormQueuesTest.java 2008-11-19
16:33:07 UTC (rev 11240)
@@ -0,0 +1,66 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+package org.ajax4jsf;
+
+
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.0
+ *
+ */
+public class AjaxFormQueuesTest extends AbstractQueueComponentTest {
+
+ /**
+ * @param name
+ */
+ public AjaxFormQueuesTest(String name) {
+ super(name);
+ }
+
+ protected void checkForm(String formName) throws Exception {
+ renderView("/ajax-form.xhtml");
+ executeJavaScript("$('" + formName + ":link').click()");
+ executeTimer();
+
+ Object resultObject = executeJavaScript("window.testResults." + formName);
+
+ assertTrue(formName, resultObject instanceof Boolean && (Boolean)
resultObject);
+ }
+
+ public void testViewDefault() throws Exception {
+ checkForm("viewDefault");
+ }
+
+ public void testViewNamed() throws Exception {
+ checkForm("viewNamed");
+ }
+
+ public void testFormDefault() throws Exception {
+ checkForm("formDefault");
+ }
+
+ public void testFormNamed() throws Exception {
+ checkForm("formNamed");
+ }
+}
Copied: trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/ImplicitQueuesTest.java (from
rev 11238, trunk/sandbox/ui/queue/src/test/java/org/richfaces/ImplicitQueuesTest.java)
===================================================================
--- trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/ImplicitQueuesTest.java
(rev 0)
+++ trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/ImplicitQueuesTest.java 2008-11-19
16:33:07 UTC (rev 11240)
@@ -0,0 +1,112 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf;
+
+import java.util.List;
+
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.0
+ *
+ */
+public class ImplicitQueuesTest extends AbstractQueueComponentTest {
+
+ /**
+ * @param name
+ */
+ public ImplicitQueuesTest(String name) {
+ super(name);
+ }
+
+ public void testImplicitGlobalQueueEnabled() throws Exception {
+ servletContext.addInitParameter("org.richfaces.queue.global.enabled",
"true");
+
+ renderView();
+
+ ajax("a", createAjaxParameters().requestTime(1000));
+ ajax("b", createAjaxParameters().requestTime(1000));
+
+ TestsResult result = getTestsResult();
+ assertEquals(2000d, result.getCurrentTime());
+ }
+
+ public void testImplicitGlobalQueueDefault() throws Exception {
+ renderView();
+
+ ajax("a", createAjaxParameters().requestTime(1000));
+ ajax("b", createAjaxParameters().requestTime(1000));
+
+ TestsResult result = getTestsResult();
+ assertEquals(1000d, result.getCurrentTime());
+ }
+
+ public void testLegacyQueuesRequestDelay() throws Exception {
+ renderView("/legacy.xhtml");
+
+ executeAfterDelay("$('form:buttonDelayed').click()");
+ delay(500);
+ executeAfterDelay("$('form:buttonDelayed').click()");
+ delay(250);
+ executeAfterDelay("$('form:buttonDelayed').click()");
+
+ TestsResult result = getTestsResult();
+ List<RequestData> dataList = result.getDataList();
+ assertEquals(1, dataList.size());
+
+ //request time set to 5000 in .xhtml file
+ RequestData data = dataList.get(0);
+ assertRequestData(data, null, 1750, 6750, false);
+
+ assertEquals(6750d, result.getCurrentTime());
+ }
+
+ public void testLegacyQueuesIgnoreDupResponces() throws Exception {
+ renderView("/legacy.xhtml");
+
+ executeAfterDelay("$('form:buttonIgnoreDupResponces').click()");
+ delay(500);
+
+ executeAfterDelay("$('form:buttonIgnoreDupResponces').click()");
+ delay(250);
+
+ executeAfterDelay("$('form:buttonIgnoreDupResponces').click()");
+
+ executeTimer();
+ TestsResult result = getTestsResult();
+ List<RequestData> dataList = result.getDataList();
+ assertEquals(3, dataList.size());
+
+ //request time set to 5000 in .xhtml file
+ assertRequestData(dataList.get(0), null, 0, 5000, false);
+ assertRequestData(dataList.get(1), null, 500, 5500, false);
+ assertRequestData(dataList.get(2), null, 750, 5750, false);
+
+ assertEquals(5750d, result.getCurrentTime());
+
+ Double requestsCompletedCounter = (Double) executeJavaScript("counter");
+ assertEquals(1d, requestsCompletedCounter);
+
+ Double requestsCompletionTime = (Double) executeJavaScript("time");
+ assertEquals(5750d, requestsCompletionTime);
+ }
+}
Copied: trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/QueueDiscoveryTest.java (from
rev 11238, trunk/sandbox/ui/queue/src/test/java/org/richfaces/QueueDiscoveryTest.java)
===================================================================
--- trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/QueueDiscoveryTest.java
(rev 0)
+++ trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/QueueDiscoveryTest.java 2008-11-19
16:33:07 UTC (rev 11240)
@@ -0,0 +1,215 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.mozilla.javascript.NativeArray;
+
+import com.gargoylesoftware.htmlunit.ScriptResult;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.0
+ *
+ */
+public class QueueDiscoveryTest extends AbstractQueueComponentTest {
+
+ /**
+ * @param name
+ */
+ public QueueDiscoveryTest(String name) {
+ super(name);
+ }
+
+ protected void assertListsEqual(List<String> list1, List<String> list2)
+ throws Exception {
+
+ System.out.println(list1);
+ System.out.println(list2);
+ System.out.println("xxx");
+ assertEquals(list1, list2);
+ }
+
+ protected List<String> getResults(HtmlPage page) {
+ List<String> result = new ArrayList<String>();
+
+ page.executeJavaScript("Timer.execute()");
+ ScriptResult scriptResult = page.executeJavaScript("window.testResult");
+ NativeArray array = (NativeArray) scriptResult.getJavaScriptResult();
+ for (int i = 0; i < array.getLength(); i++) {
+ result.add((String) array.get(i, array));
+ }
+
+ return result;
+ }
+
+ public void testGlobalViewQueue() throws Exception {
+ renderView("/global-view.xhtml");
+
+ List<String> list = new ArrayList<String>();
+ assertListsEqual(list, getResults(page));
+
+ list.add("button");
+ page.executeJavaScript("$('form:button').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("implicitQueue");
+ page.executeJavaScript("$('form:implicitQueue').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("alternativeQueueButton");
+ list.add("alt:alternativeQueueButton");
+ page.executeJavaScript("$('form:alternativeQueueButton').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("function");
+ page.executeJavaScript("ajaxFunction()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("implicitDelayedQueue");
+ page.executeJavaScript("$('form2:implicitDelayedQueue').click()");
+ assertListsEqual(list, getResults(page));
+ }
+
+ public void testGlobalFormQueue() throws Exception {
+ renderView("/global-form.xhtml");
+
+ List<String> list = new ArrayList<String>();
+ assertListsEqual(list, getResults(page));
+
+ list.add("alternativeQueueButton");
+ list.add("alt:alternativeQueueButton");
+ page.executeJavaScript("$('form2:alternativeQueueButton').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("alternativeQueueButton");
+ page.executeJavaScript("$('form:alternativeQueueButton').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("buttonFormQueue");
+ page.executeJavaScript("$('form:button').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("implicitQueue");
+ page.executeJavaScript("$('form:implicitQueue').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("alternativeQueue1Button");
+ list.add("alt1:alternativeQueue1Button");
+ page.executeJavaScript("$('form:alternativeQueue1Button').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("buttonForm2Queue");
+ page.executeJavaScript("$('form2:button').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("implicitDelayedQueue");
+ page.executeJavaScript("$('form2:implicitDelayedQueue').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("ajaxFunction");
+ page.executeJavaScript("ajaxFunction()");
+ assertListsEqual(list, getResults(page));
+ }
+
+ public void testGlobalFormBoth() throws Exception {
+ renderView("/global-both.xhtml");
+
+ List<String> list = new ArrayList<String>();
+ assertListsEqual(list, getResults(page));
+
+ list.add("buttonFormQueue");
+ page.executeJavaScript("$('form:button').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("implicitDelayedQueue");
+ page.executeJavaScript("$('form:implicitDelayedQueue').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("implicitQueue");
+ page.executeJavaScript("$('form2:implicitQueue').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("viewQueue:viewQueueButton");
+ page.executeJavaScript("$('form:viewQueueButton').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("form2Button");
+ page.executeJavaScript("$('form2:button').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("anotherImplicitQueue");
+ page.executeJavaScript("$('form3:anotherImplicitQueue').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("form3Button");
+ page.executeJavaScript("$('form3:button').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("functionFormQueue");
+ page.executeJavaScript("ajaxFunction()");
+ assertListsEqual(list, getResults(page));
+ }
+
+ public void testDisabled() throws Exception {
+ renderView("/disabled.xhtml");
+
+ List<String> list = new ArrayList<String>();
+ assertListsEqual(list, getResults(page));
+
+ list.add("button");
+ page.executeJavaScript("$('form:button').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("formQueueButton");
+ page.executeJavaScript("$('form:formQueueButton').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("button2");
+ list.add("form2-global:button2");
+ page.executeJavaScript("$('form2:button2').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("formQueueButton2");
+ list.add("form2-queue:formQueueButton2");
+ page.executeJavaScript("$('form2:formQueueButton2').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("global");
+ page.executeJavaScript("$('form3:global').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("globalNamed");
+ page.executeJavaScript("$('form3:globalNamed').click()");
+ assertListsEqual(list, getResults(page));
+
+ list.add("globalNamedX");
+ list.add("viewNamedX:globalNamedX");
+ page.executeJavaScript("$('form3:globalNamedX').click()");
+ assertListsEqual(list, getResults(page));
+ }
+
+}
Deleted: trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/ScriptTest.java
===================================================================
--- trunk/sandbox/ui/queue/src/test/java/org/richfaces/ScriptTest.java 2008-11-17 11:24:50
UTC (rev 11187)
+++ trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/ScriptTest.java 2008-11-19 16:33:07
UTC (rev 11240)
@@ -1,51 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-
-package org.richfaces;
-
-import com.gargoylesoftware.htmlunit.html.HtmlPage;
-
-/**
- * @author mikalaj
- *
- */
-public class ScriptTest extends AbstractQueueComponentTest {
-
- public ScriptTest(String name) {
- super(name);
- }
-
- public void testScript() throws Exception {
- buildView("/script.xhtml");
-
- delay(500);
- ajax("a", "{requestDelay: 1000, requestId: '12', requestTime:
1500}");
- delay(4100);
- ajax("b", "{requestDelay: 4100, requestId: '12', requestTime:
101, timeout: 10}");
-
-
- HtmlPage page = this.renderView();
- assertNotNull(page);
-
- System.out.println(getTestsResult(page));
- }
-}
Copied: trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/ScriptTest.java (from rev 11238,
trunk/sandbox/ui/queue/src/test/java/org/richfaces/ScriptTest.java)
===================================================================
--- trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/ScriptTest.java
(rev 0)
+++ trunk/sandbox/ui/queue/src/test/java/org/ajax4jsf/ScriptTest.java 2008-11-19 16:33:07
UTC (rev 11240)
@@ -0,0 +1,111 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+package org.ajax4jsf;
+
+import java.util.List;
+
+/**
+ * @author Denis Morozov
+ * @author Nick Belaevski
+ */
+public class ScriptTest extends AbstractQueueComponentTest {
+
+ private static final String QUEUE_NAME = "testQueue";
+
+ private static final String VIEW_NAME = "/script.xhtml";
+
+ public ScriptTest(String name) {
+ super(name);
+ }
+
+ public void testSimpleAjax() throws Exception {
+ renderView(VIEW_NAME);
+
+ delay(50);
+ ajax("a", createAjaxParameters().requestTime(100));
+ ajax("b", createAjaxParameters().requestTime(150));
+
+ TestsResult result = getTestsResult();
+ List<RequestData> dataList = result.getDataList();
+ assertEquals(2, dataList.size());
+ assertRequestData(dataList.get(0), "a", 50, 150, false);
+ assertRequestData(dataList.get(1), "b", 50, 200, false);
+
+ assertEquals(200d, result.getCurrentTime());
+ }
+
+ public void testSimpleQueuedAjax() throws Exception {
+ renderView(VIEW_NAME);
+
+ delay(50);
+ ParametersBuilder queueParameters =
createAjaxParameters().requestTime(500).eventsQueue(QUEUE_NAME);
+ ajax("a", queueParameters.requestId(0));
+ delay(200);
+ ajax("b", queueParameters.requestId(1));
+
+ TestsResult result = getTestsResult();
+ List<RequestData> dataList = result.getDataList();
+ assertEquals(2, dataList.size());
+ assertRequestData(dataList.get(0), "a", 50, 550, false);
+ assertRequestData(dataList.get(1), "b", 550, 1050, false);
+
+ assertEquals(1050d, result.getCurrentTime());
+ }
+
+ public void testScript() throws Exception {
+ renderView(VIEW_NAME);
+
+ delay(500);
+ ajax("a", "{requestDelay: 100, requestId: '12', requestTime:
100, eventsQueue: 'q'}");
+ delay(4100);
+ ajax("b", "{requestDelay: 4400, requestId: '12', requestTime:
101, timeout: 10, eventsQueue: 'q'}");
+ ajax("c", "{requestDelay: 0, requestId: '123', requestTime: 1,
timeout: 10, eventsQueue: 'q'}");
+
+ System.out.println(getTestsResult());
+ }
+
+ public void testImplicitQueue() throws Exception {
+ renderView(VIEW_NAME);
+
+ ParametersBuilder parameters = createAjaxParameters().
+ requestDelay(100).
+ implicitEventsQueue("myqueue").
+ requestTime(10);
+
+ ajax("a", parameters);
+ delay(10);
+ ajax("b", parameters);
+ delay(10);
+ ajax("c", parameters.requestDelay(50));
+
+ TestsResult result = getTestsResult();
+ List<RequestData> dataList = result.getDataList();
+ assertEquals(1, dataList.size());
+
+ RequestData requestData = dataList.get(0);
+ assertRequestData(requestData, "c", 70, 80, false);
+
+ assertEquals(80d, result.getCurrentTime());
+
+ }
+}
Copied: trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf (from rev 11187,
trunk/sandbox/ui/queue/src/test/resources/org/richfaces)
Property changes on: trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/ajax-form.xhtml (from rev
11238, trunk/sandbox/ui/queue/src/test/resources/org/richfaces/ajax-form.xhtml)
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/ajax-form.xhtml
(rev 0)
+++ trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/ajax-form.xhtml 2008-11-19
16:33:07 UTC (rev 11240)
@@ -0,0 +1,47 @@
+<html
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:q="http://labs.jboss.com/jbossrichfaces/ui/ui/queue">
+ <head>
+ <title>a4j:form check page</title>
+ </head>
+ <body>
+ <f:view>
+ <script type="text/javascript">
+ function $(name) {
+ return document.getElementById(name);
+ }
+
+ window.testResults = {};
+ </script>
+
+ <a4j:status startText="...running..." startStyle="color: green"
/>
+
+ <q:queue oncomplete="window.testResults.viewDefault = true"/>
+
+ <a4j:form ajaxSubmit="true" id="viewDefault">
+ <h:commandButton value="view default queue" id="link" />
+ </a4j:form>
+
+ <q:queue oncomplete="window.testResults.viewNamed = true"
name="viewNamed" />
+
+ <a4j:form ajaxSubmit="true" eventsQueue="viewNamed"
id="viewNamed">
+ <h:commandButton value="view named queue" id="link" />
+ </a4j:form>
+
+ <a4j:form ajaxSubmit="true" id="formDefault">
+ <q:queue oncomplete="window.testResults.formDefault = true" />
+
+ <h:commandButton value="form default queue" id="link" />
+ </a4j:form>
+
+ <a4j:form ajaxSubmit="true" eventsQueue="formQueue"
id="formNamed">
+ <q:queue oncomplete="window.testResults.formNamed = true"
name="formQueue" />
+
+ <h:commandButton value="form named queue" id="link" />
+ </a4j:form>
+ </f:view>
+ </body>
+</html>
Copied: trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/disabled.xhtml (from rev
11238, trunk/sandbox/ui/queue/src/test/resources/org/richfaces/disabled.xhtml)
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/disabled.xhtml
(rev 0)
+++ trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/disabled.xhtml 2008-11-19
16:33:07 UTC (rev 11240)
@@ -0,0 +1,60 @@
+<html
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:q="http://labs.jboss.com/jbossrichfaces/ui/ui/queue">
+ <body>
+ <f:view>
+ <ui:include src="discovery-base.xhtml" />
+
+ <h:form id="form">
+ <a4j:commandButton id="button"
oncomplete="addResult('button')">
+ <f:param name="data" value="button" />
+ </a4j:commandButton>
+ <a4j:commandButton id="formQueueButton"
oncomplete="addResult('formQueueButton')"
eventsQueue="form">
+ <f:param name="data" value="formQueueButton" />
+ </a4j:commandButton>
+
+ <q:queue oncomplete="addResult('disabled')"
disabled="true" />
+ <q:queue oncomplete="addResult('disabledForm')"
name="form" disabled="true" />
+ </h:form>
+
+ <h:form id="form2">
+ <a4j:commandButton id="button2"
oncomplete="addResult('button2')">
+ <f:param name="data" value="button2" />
+ </a4j:commandButton>
+ <a4j:commandButton id="formQueueButton2"
oncomplete="addResult('formQueueButton2')"
eventsQueue="form2">
+ <f:param name="data" value="formQueueButton2" />
+ </a4j:commandButton>
+
+ <q:queue oncomplete="addResult('disabledA')"
disabled="true" />
+ <q:queue oncomplete="addResult('form2-global:' +
request.options.parameters.data)" />
+ <q:queue oncomplete="addResult('disabledB')"
disabled="true" />
+
+ <q:queue oncomplete="addResult('disabledA1')"
disabled="true" name="form2" />
+ <q:queue oncomplete="addResult('form2-queue:' +
request.options.parameters.data)" name="form2"/>
+ <q:queue oncomplete="addResult('disabledB1')"
disabled="true" name="form2" />
+ </h:form>
+
+ <h:form id="form3">
+ <a4j:commandButton id="global"
oncomplete="addResult('global')">
+ <f:param name="data" value="global" />
+ </a4j:commandButton>
+ <a4j:commandButton id="globalNamed"
oncomplete="addResult('globalNamed')"
eventsQueue="viewNamed">
+ <f:param name="data" value="globalNamed" />
+ </a4j:commandButton>
+ <a4j:commandButton id="globalNamedX"
oncomplete="addResult('globalNamedX')"
eventsQueue="viewNamedX">
+ <f:param name="data" value="globalNamedX" />
+ </a4j:commandButton>
+ </h:form>
+
+ <q:queue oncomplete="addResult('disabled:' +
request.options.parameters.data)" disabled="true" />
+ <q:queue oncomplete="addResult('viewNamed:' +
request.options.parameters.data)" name="viewNamed"
disabled="true" />
+
+ <q:queue oncomplete="addResult('viewNamedXA:' +
request.options.parameters.data)" name="viewNamedX"
disabled="true" />
+ <q:queue oncomplete="addResult('viewNamedX:' +
request.options.parameters.data)" name="viewNamedX" />
+ <q:queue oncomplete="addResult('viewNamedXB:' +
request.options.parameters.data)" name="viewNamedX"
disabled="true" />
+ </f:view>
+ </body>
+</html>
Copied: trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/discovery-base.xhtml (from
rev 11238, trunk/sandbox/ui/queue/src/test/resources/org/richfaces/discovery-base.xhtml)
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/discovery-base.xhtml
(rev 0)
+++ trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/discovery-base.xhtml 2008-11-19
16:33:07 UTC (rev 11240)
@@ -0,0 +1,23 @@
+<ui:composition
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:q="http://labs.jboss.com/jbossrichfaces/ui/ui/queue">
+
+ <script type="text/javascript">
+ function $(id) {
+ return document.getElementById(id);
+ }
+
+ window.testResult = new Array();
+
+ function addResult(value) {
+ window.testResult.push(value);
+ }
+
+ function stub() {
+ }
+ </script>
+
+ <a4j:status startText="...running..." startStyle="color: green"
/>
+</ui:composition>
Copied: trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/global-both.xhtml (from rev
11238, trunk/sandbox/ui/queue/src/test/resources/org/richfaces/global-both.xhtml)
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/global-both.xhtml
(rev 0)
+++ trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/global-both.xhtml 2008-11-19
16:33:07 UTC (rev 11240)
@@ -0,0 +1,66 @@
+<html
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:q="http://labs.jboss.com/jbossrichfaces/ui/ui/queue">
+ <body>
+ <f:view>
+ <ui:include src="discovery-base.xhtml" />
+
+ <q:queue oncomplete="addResult(request.options.parameters.data)"/>
+
+ <h:form id="form">
+ <q:queue oncomplete="addResult('buttonFormQueue')"/>
+
+ <a4j:commandButton id="button" oncomplete="stub()">
+ <f:param name="data" value="button" />
+ </a4j:commandButton>
+
+ <a4j:commandButton id="viewQueueButton" oncomplete="stub()"
eventsQueue="viewQueue">
+ <f:param name="data" value="viewQueueButton" />
+ </a4j:commandButton>
+
+ <a4j:commandButton id="implicitDelayedQueue"
requestDelay="500"
+ eventsQueue="implicitDelayedQueue"
oncomplete="addResult('implicitDelayedQueue')">
+ <f:param name="data" value="implicitDelayedQueue" />
+ </a4j:commandButton>
+ </h:form>
+
+ <h:form id="form2">
+ <a4j:commandButton id="formQueueButton"
eventsQueue="formQueue" requestDelay="1000"
oncomplete="stub()">
+ <f:param name="data" value="formQueueButton" />
+ </a4j:commandButton>
+
+ <q:queue oncomplete="addResult('formQueue:' +
request.options.parameters.data)" name="formQueue"/>
+
+ <a4j:commandButton id="button" requestDelay="1000"
oncomplete="stub()">
+ <f:param name="data" value="form2Button" />
+ </a4j:commandButton>
+
+ <a4j:commandButton id="implicitQueue"
eventsQueue="implicitQueue"
oncomplete="addResult('implicitQueue')">
+ <f:param name="data" value="implicitQueue" />
+ </a4j:commandButton>
+ </h:form>
+
+ <h:form id="form3">
+
+ <a4j:commandButton id="button">
+ <f:param name="data" value="form3Button" />
+ </a4j:commandButton>
+
+ <a4j:commandButton id="anotherImplicitQueue"
ignoreDupResponses="true" eventsQueue="anotherImplicitQueue"
oncomplete="addResult('anotherImplicitQueue')">
+ <f:param name="data" value="anotherImplicitQueue" />
+ </a4j:commandButton>
+ </h:form>
+
+ <h:form>
+ <q:queue oncomplete="addResult('functionFormQueue')"/>
+
+ <a4j:jsFunction name="ajaxFunction" />
+ </h:form>
+
+ <q:queue oncomplete="addResult('viewQueue:' +
request.options.parameters.data)" name="viewQueue"/>
+ </f:view>
+ </body>
+</html>
Copied: trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/global-form.xhtml (from rev
11238, trunk/sandbox/ui/queue/src/test/resources/org/richfaces/global-form.xhtml)
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/global-form.xhtml
(rev 0)
+++ trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/global-form.xhtml 2008-11-19
16:33:07 UTC (rev 11240)
@@ -0,0 +1,54 @@
+<html
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:q="http://labs.jboss.com/jbossrichfaces/ui/ui/queue">
+ <body>
+ <f:view>
+ <ui:include src="discovery-base.xhtml" />
+
+ <h:form id="form">
+ <q:queue oncomplete="addResult('alt1:' +
request.options.parameters.data)" name="alternativeQueue1" />
+ <q:queue oncomplete="addResult('buttonFormQueue')"/>
+
+ <a4j:commandButton id="button" oncomplete="stub()">
+ <f:param name="data" value="button" />
+ </a4j:commandButton>
+
+ <a4j:commandButton id="implicitQueue"
eventsQueue="implicitQueue"
oncomplete="addResult('implicitQueue')">
+ <f:param name="data" value="implicitQueue" />
+ </a4j:commandButton>
+
+ <a4j:commandButton id="alternativeQueueButton"
eventsQueue="alternativeQueue"
oncomplete="addResult('alternativeQueueButton')">
+ <f:param name="data" value="alternativeQueueButton" />
+ </a4j:commandButton>
+
+ <a4j:commandButton id="alternativeQueue1Button"
eventsQueue="alternativeQueue1"
oncomplete="addResult('alternativeQueue1Button')">
+ <f:param name="data" value="alternativeQueue1Button" />
+ </a4j:commandButton>
+
+ </h:form>
+
+ <h:form>
+ <a4j:jsFunction name="ajaxFunction"
oncomplete="addResult('ajaxFunction')"/>
+ </h:form>
+
+
+ <h:form id="form2">
+ <a4j:commandButton id="button" requestDelay="1000"
oncomplete="stub()" />
+ <a4j:commandButton id="implicitDelayedQueue"
requestDelay="500"
+ eventsQueue="implicitDelayedQueue"
oncomplete="addResult('implicitDelayedQueue')">
+ <f:param name="data" value="implicitDelayedQueue" />
+ </a4j:commandButton>
+
+ <a4j:commandButton id="alternativeQueueButton"
eventsQueue="alternativeQueue"
oncomplete="addResult('alternativeQueueButton')">
+ <f:param name="data" value="alternativeQueueButton" />
+ </a4j:commandButton>
+
+ <q:queue oncomplete="addResult('buttonForm2Queue')"/>
+ <q:queue oncomplete="addResult('alt:' +
request.options.parameters.data)" name="alternativeQueue" />
+ </h:form>
+ </f:view>
+ </body>
+</html>
Copied: trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/global-view.xhtml (from rev
11238, trunk/sandbox/ui/queue/src/test/resources/org/richfaces/global-view.xhtml)
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/global-view.xhtml
(rev 0)
+++ trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/global-view.xhtml 2008-11-19
16:33:07 UTC (rev 11240)
@@ -0,0 +1,41 @@
+<html
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:q="http://labs.jboss.com/jbossrichfaces/ui/ui/queue">
+ <body>
+ <f:view>
+ <ui:include src="discovery-base.xhtml" />
+
+ <h:form id="form">
+ <a4j:commandButton id="button" oncomplete="stub()"
requestDelay="100">
+ <f:param name="data" value="button" />
+ </a4j:commandButton>
+
+ <a4j:commandButton id="alternativeQueueButton"
eventsQueue="alternativeQueue"
oncomplete="addResult('alternativeQueueButton')">
+ <f:param name="data" value="alternativeQueueButton" />
+ </a4j:commandButton>
+
+ <a4j:commandButton id="implicitQueue"
eventsQueue="implicitQueue"
oncomplete="addResult('implicitQueue')">
+ <f:param name="data" value="implicitQueue" />
+ </a4j:commandButton>
+ </h:form>
+
+ <h:form id="form2">
+ <a4j:jsFunction name="ajaxFunction" oncomplete="stub()">
+ <f:param name="data" value="function" />
+ </a4j:jsFunction>
+
+ <a4j:commandButton id="implicitDelayedQueue"
requestDelay="500"
+ eventsQueue="implicitDelayedQueue"
oncomplete="addResult('implicitDelayedQueue')">
+ <f:param name="data" value="implicitDelayedQueue" />
+ </a4j:commandButton>
+ </h:form>
+
+ <q:queue oncomplete="addResult(request.options.parameters.data)"/>
+ <q:queue oncomplete="addResult('alt:' +
request.options.parameters.data)" name="alternativeQueue" />
+
+ </f:view>
+ </body>
+</html>
Copied: trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/implicit-global-queue.xhtml
(from rev 11238,
trunk/sandbox/ui/queue/src/test/resources/org/richfaces/implicit-global-queue.xhtml)
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/implicit-global-queue.xhtml
(rev 0)
+++
trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/implicit-global-queue.xhtml 2008-11-19
16:33:07 UTC (rev 11240)
@@ -0,0 +1,11 @@
+<html
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:q="http://labs.jboss.com/jbossrichfaces/ui/ui/queue">
+ <body>
+ <f:view>
+ </f:view>
+ </body>
+</html>
Copied: trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/legacy.xhtml (from rev
11238, trunk/sandbox/ui/queue/src/test/resources/org/richfaces/legacy.xhtml)
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/legacy.xhtml
(rev 0)
+++ trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/legacy.xhtml 2008-11-19
16:33:07 UTC (rev 11240)
@@ -0,0 +1,25 @@
+<html
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:q="http://labs.jboss.com/jbossrichfaces/ui/ui/queue">
+ <body>
+ <f:view>
+ <script type="text/javascript">
+ XMLHttpRequest.defaultRequestTime = 5000;
+
+ function $(id) {
+ return document.getElementById(id);
+ }
+
+ var counter = 0;
+ var time = 0;
+ </script>
+ <h:form id="form">
+ <a4j:commandButton id="buttonDelayed" requestDelay="1000"
/>
+ <a4j:commandButton id="buttonIgnoreDupResponces"
ignoreDupResponses="true" oncomplete="counter++;time =
Timer.currentTime;"/>
+ </h:form>
+ </f:view>
+ </body>
+</html>
Deleted: trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/simulation.js
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/richfaces/simulation.js 2008-11-17
11:24:50 UTC (rev 11187)
+++ trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/simulation.js 2008-11-19
16:33:07 UTC (rev 11240)
@@ -1,120 +0,0 @@
-var Timer = {
-
- _eventCounter: 0,
-
- currentTime: 0,
-
- maxTime: 100000,
-
- events: new Array(),
-
- addEventToTimer: function(callback, delay) {
- var eventTime = this.currentTime + delay;
-
- var i = 0;
-
- while (this.events[i] && (this.events[i].eventTime <= eventTime)) {
- i++;
- }
-
- var eventId = this._eventCounter++;
-
- this.events.splice(i, 0, {eventTime: eventTime, callback: callback, eventId:
eventId});
-
- return eventId;
- },
-
- removeEventFromTimer: function(eventId) {
- for ( var i = 0; i < this.events.length; i++) {
- if (this.events[i].eventId == eventId) {
- this.events.splice(i, 1);
-
- break;
- }
- }
- },
-
- execute: function() {
- while (this.events.length > 0) {
- var eventData = this.events.shift();
-
- this.currentTime = eventData.eventTime;
- if (this.currentTime > this.maxTime) {
- throw "Maximum execution time reached, aborting timer";
- }
-
- try {
-
- eventData.callback();
- } catch (e) {
- alert(e.message);
- }
- }
- },
-
- isEmpty: function() {
- return this.events.length == 0;
- }
-};
-
-window.setTimeout = function(callback, delay) {
- return Timer.addEventToTimer(callback, delay);
-}
-
-window.clearTimeout = function(timerId) {
- Timer.removeEventFromTimer(timerId);
-}
-
-window.simulationContext = {
-
- results: new Array(),
-
- delay: 0,
-
- wait: function(delay) {
- this.delay += delay;
- },
-
- ajax: function() {
- var args = arguments;
- ajaxSubmit(args[0], args[1]);
-
- Timer.addEventToTimer(function() {
- ajaxSubmit(args[0], args[1]);
- }, this.delay);
- }
- };
-
-A4J.AJAX.SubmitQuery = function(query, options) {
- var request = {};
-
- var length = window.simulationContext.results.push({data: options.data, startTime:
Timer.currentTime});
-
- var timer = Timer.addEventToTimer(function() {
- if (request.timeoutTimer) {
- Timer.removeEventFromTimer(request.timeoutTimer);
- }
-
- if (request.queue) {
- request.queue.pop();
- }
-
- window.simulationContext.results[length - 1].endTime = Timer.currentTime;
-
- }, options.requestTime);
-
- if (options.timeout) {
- request.timeoutTimer = Timer.addEventToTimer(function() {
- Timer.removeEventFromTimer(timer);
- if (request.queue) {
- request.queue.pop();
- }
-
- window.simulationContext.results[length - 1].timedOut = true;
- window.simulationContext.results[length - 1].endTime = Timer.currentTime;
- }, options.timeout);
- }
-
- return request;
-}
-
Copied: trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/simulation.js (from rev
11238, trunk/sandbox/ui/queue/src/test/resources/org/richfaces/simulation.js)
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/simulation.js
(rev 0)
+++ trunk/sandbox/ui/queue/src/test/resources/org/ajax4jsf/simulation.js 2008-11-19
16:33:07 UTC (rev 11240)
@@ -0,0 +1,173 @@
+var Timer = {
+
+ _eventCounter: 0,
+
+ currentTime: 0,
+
+ maxTime: 100000,
+
+ events: new Array(),
+
+ addEventToTimer: function(callback, delay) {
+ var eventTime = this.currentTime + delay;
+
+ var i = 0;
+
+ while (this.events[i] && (this.events[i].eventTime <= eventTime)) {
+ i++;
+ }
+
+ var eventId = this._eventCounter++;
+
+ this.events.splice(i, 0, {eventTime: eventTime, callback: callback, eventId:
eventId});
+
+ return eventId;
+ },
+
+ removeEventFromTimer: function(eventId) {
+ for ( var i = 0; i < this.events.length; i++) {
+ if (this.events[i].eventId == eventId) {
+ this.events.splice(i, 1);
+
+ break;
+ }
+ }
+ },
+
+ execute: function() {
+ while (this.events.length > 0) {
+ var eventData = this.events.shift();
+
+ this.currentTime = eventData.eventTime;
+ if (this.currentTime > this.maxTime) {
+ throw "Maximum execution time reached, aborting timer";
+ }
+
+ try {
+
+ eventData.callback();
+ } catch (e) {
+ alert(e.message);
+ }
+ }
+ },
+
+ isEmpty: function() {
+ return this.events.length == 0;
+ }
+};
+
+window.setTimeout = function(callback, delay) {
+ return Timer.addEventToTimer(callback, delay);
+}
+
+window.clearTimeout = function(timerId) {
+ Timer.removeEventFromTimer(timerId);
+}
+
+var SimulationContext = function(submitFunction) {
+ this.results = new Array();
+ this.time = 0;
+
+ this.submitFunction = submitFunction;
+};
+
+SimulationContext.prototype.wait = function(delay) {
+ this.time += delay;
+};
+
+SimulationContext.prototype.ajax = function() {
+ var args = arguments;
+ var _this = this;
+
+ Timer.addEventToTimer(function() {
+ _this.submitFunction(args[0], args[1]);
+ }, this.time);
+};
+
+SimulationContext.prototype.executeAfterDelay = function(code) {
+ Timer.addEventToTimer(function() {
+ code();
+ }, this.time);
+};
+
+window.simulationContext = undefined;
+
+window.XMLHttpRequest = function() {
+ this.requestTime = XMLHttpRequest.requestTime || 0;
+ this.data = XMLHttpRequest.data;
+
+ this.responseText = null;
+ this.responseXML = null;
+
+ this.readyState = 0;
+}
+
+window.XMLHttpRequest.UNSENT = 0;
+window.XMLHttpRequest.OPENED = 1;
+window.XMLHttpRequest.HEADERS_RECEIVED = 2;
+window.XMLHttpRequest.LOADING = 3;
+window.XMLHttpRequest.DONE = 4;
+
+XMLHttpRequest.prototype.abort = function() {
+ if (this.timerId) {
+ clearTimeout(this.timerId);
+ }
+
+ window.simulationContext.results[this.requestId].endTime = Timer.currentTime;
+ window.simulationContext.results[this.requestId].aborted = true;
+};
+
+XMLHttpRequest.prototype.getAllResponseHeaders = function() {
+ return "";
+};
+XMLHttpRequest.prototype.getResponseHeader = function(name) {
+ if ("Ajax-Response" == name) {
+ return "true";
+ }
+ return "";
+};
+XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
+ this.readyState = XMLHttpRequest.OPENED;
+};
+
+XMLHttpRequest.prototype.send = function(contentType) {
+ var length = window.simulationContext.results.push({data: this.data, startTime:
Timer.currentTime});
+ this.requestId = length - 1;
+
+ var _this = this;
+ this.timerId = setTimeout(function() {
+ _this.status = 200;
+ _this.statusText = "Success";
+ _this.readyState = window.XMLHttpRequest.DONE;
+ _this.responseText = "<?xml version='1.0'?><html />";
+
+ var doc = new ActiveXObject("MSXML.DOMDocument");
+ doc.loadXML(_this.responseText);
+ _this.responseXML = doc;
+
+ window.simulationContext.results[_this.requestId].endTime = Timer.currentTime;
+ _this.onreadystatechange();
+ }, this.requestTime);
+};
+
+XMLHttpRequest.prototype.setRequestHeader = function(name, value) {
+
+};
+
+var oldSubmitQuery = A4J.AJAX.SubmitQuery;
+
+A4J.AJAX.SubmitQuery = function(query, options) {
+ XMLHttpRequest.requestTime = options.requestTime || XMLHttpRequest.defaultRequestTime;
+ XMLHttpRequest.data = options.data;
+
+ try {
+ var req = oldSubmitQuery.apply(this, arguments);
+
+ return req;
+ } finally {
+ XMLHttpRequest.requestTime = undefined;
+ XMLHttpRequest.data = undefined;
+ }
+}
+