JBoss Rich Faces SVN: r11240 - in trunk/sandbox/ui/queue/src: main/java/org/ajax4jsf and 9 other directories.
by richfaces-svn-commits@lists.jboss.org
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;
+ }
+}
+
17 years, 6 months
JBoss Rich Faces SVN: r11239 - trunk/framework/impl/src/main/java/org/ajax4jsf/component.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2008-11-19 11:31:41 -0500 (Wed, 19 Nov 2008)
New Revision: 11239
Added:
trunk/framework/impl/src/main/java/org/ajax4jsf/component/UIQueue.java
Log:
Queue refactored to org.ajax4jsf.*
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/component/UIQueue.java (from rev 11221, trunk/sandbox/ui/queue/src/main/java/org/richfaces/component/UIQueue.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/component/UIQueue.java (rev 0)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/component/UIQueue.java 2008-11-19 16:31:41 UTC (rev 11239)
@@ -0,0 +1,98 @@
+/**
+ * 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.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.ajax4jsf.Queue";
+
+ public static final String COMPONENT_FAMILY = "org.ajax4jsf.Queue";
+
+ //TODO rename to org.ajax4jsf?
+ 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;
+ }
+}
Property changes on: trunk/framework/impl/src/main/java/org/ajax4jsf/component/UIQueue.java
___________________________________________________________________
Name: svn:mergeinfo
+
17 years, 6 months
JBoss Rich Faces SVN: r11238 - in trunk/sandbox: samples/queue-sample/src/main/webapp/templates and 3 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2008-11-19 11:21:37 -0500 (Wed, 19 Nov 2008)
New Revision: 11238
Added:
trunk/sandbox/ui/queue/src/test/java/org/richfaces/AjaxFormQueuesTest.java
trunk/sandbox/ui/queue/src/test/java/org/richfaces/ImplicitQueuesTest.java
trunk/sandbox/ui/queue/src/test/java/org/richfaces/QueueDiscoveryTest.java
trunk/sandbox/ui/queue/src/test/resources/org/richfaces/ajax-form.xhtml
trunk/sandbox/ui/queue/src/test/resources/org/richfaces/disabled.xhtml
trunk/sandbox/ui/queue/src/test/resources/org/richfaces/discovery-base.xhtml
trunk/sandbox/ui/queue/src/test/resources/org/richfaces/global-both.xhtml
trunk/sandbox/ui/queue/src/test/resources/org/richfaces/global-form.xhtml
trunk/sandbox/ui/queue/src/test/resources/org/richfaces/global-view.xhtml
trunk/sandbox/ui/queue/src/test/resources/org/richfaces/implicit-global-queue.xhtml
trunk/sandbox/ui/queue/src/test/resources/org/richfaces/legacy.xhtml
Modified:
trunk/sandbox/samples/queue-sample/src/main/webapp/WEB-INF/web.xml
trunk/sandbox/samples/queue-sample/src/main/webapp/templates/index.xhtml
trunk/sandbox/ui/queue/pom.xml
trunk/sandbox/ui/queue/src/test/java/org/richfaces/AbstractQueueComponentTest.java
trunk/sandbox/ui/queue/src/test/java/org/richfaces/ScriptTest.java
trunk/sandbox/ui/queue/src/test/resources/org/richfaces/simulation.js
Log:
https://jira.jboss.org/jira/browse/RF-4970
Modified: trunk/sandbox/samples/queue-sample/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/sandbox/samples/queue-sample/src/main/webapp/WEB-INF/web.xml 2008-11-19 16:12:10 UTC (rev 11237)
+++ trunk/sandbox/samples/queue-sample/src/main/webapp/WEB-INF/web.xml 2008-11-19 16:21:37 UTC (rev 11238)
@@ -18,6 +18,17 @@
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
+
+
+ <context-param>
+ <param-name>org.richfaces.LoadStyleStrategy</param-name>
+ <param-value>DEFAULT</param-value>
+ </context-param>
+ <!-- context-param>
+ <param-name>org.richfaces.LoadScriptStrategy</param-name>
+ <param-value>NONE</param-value>
+ </context-param -->
+
<!--
-->
<filter>
Modified: trunk/sandbox/samples/queue-sample/src/main/webapp/templates/index.xhtml
===================================================================
--- trunk/sandbox/samples/queue-sample/src/main/webapp/templates/index.xhtml 2008-11-19 16:12:10 UTC (rev 11237)
+++ trunk/sandbox/samples/queue-sample/src/main/webapp/templates/index.xhtml 2008-11-19 16:21:37 UTC (rev 11238)
@@ -6,6 +6,7 @@
xmlns:q="http://labs.jboss.com/jbossrichfaces/ui/ui/queue">
<ui:composition>
+ <!-- script src="#{facesContext.externalContext.requestContextPath}/faces/a4j/g/3_3_0-SNAPSHOT/org/ajax4jsf/framework.pack.js"></script -->
<h2><ui:insert name="title" /></h2>
<ui:insert name="viewQueue" />
@@ -82,9 +83,17 @@
requestDelay="#{bean.clientRequestDelay}"
actionListener="#{bean.processActionListener}"
action="#{bean.processAction}"
+ value="formQueue - ignoreDupResponses"
+ reRender="outputText"
+ eventsQueue="formQueue" ignoreDupResponses="true"/>
+
+ <a4j:commandButton id="commandButtonFormQueueIgnoreDupResponses"
+ requestDelay="#{bean.clientRequestDelay}"
+ actionListener="#{bean.processActionListener}"
+ action="#{bean.processAction}"
value="formQueue"
reRender="outputText"
- eventsQueue="formQueue"/>
+ eventsQueue="formQueue" ignoreDupResponses="true"/>
<a4j:poll id="poll"
interval="5000"
Modified: trunk/sandbox/ui/queue/pom.xml
===================================================================
--- trunk/sandbox/ui/queue/pom.xml 2008-11-19 16:12:10 UTC (rev 11237)
+++ trunk/sandbox/ui/queue/pom.xml 2008-11-19 16:21:37 UTC (rev 11238)
@@ -32,6 +32,16 @@
</library>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <!-- TODO uncomment this -->
+ <exclude>**/ImplicitQueuesTest.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
</plugins>
</build>
<dependencies>
@@ -52,4 +62,4 @@
<version>3.3.0-SNAPSHOT</version>
</dependency>
</dependencies>
-</project>
\ No newline at end of file
+</project>
Modified: trunk/sandbox/ui/queue/src/test/java/org/richfaces/AbstractQueueComponentTest.java
===================================================================
--- trunk/sandbox/ui/queue/src/test/java/org/richfaces/AbstractQueueComponentTest.java 2008-11-19 16:12:10 UTC (rev 11237)
+++ trunk/sandbox/ui/queue/src/test/java/org/richfaces/AbstractQueueComponentTest.java 2008-11-19 16:21:37 UTC (rev 11238)
@@ -28,6 +28,8 @@
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;
@@ -50,11 +52,13 @@
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.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
import com.sun.facelets.Facelet;
@@ -74,6 +78,8 @@
private static final String AJAX_SUBMIT = "ajaxSubmit";
+ protected HtmlPage page;
+
public final static class AjaxSubmitFunctionComponent extends UIComponentBase {
@Override
@@ -112,20 +118,6 @@
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) {
@@ -155,43 +147,10 @@
@Override
public void tearDown() throws Exception {
+ this.page = null;
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 ParametersBuilder {
private Map<String, Object> parameters;
@@ -275,7 +234,7 @@
}
protected static final class RequestData {
- private boolean timedOut;
+ private boolean aborted;
private double startTime;
@@ -284,16 +243,16 @@
private String data;
public RequestData(String data, double startTime, double endTime,
- boolean timedOut) {
+ boolean aborted) {
super();
this.data = data;
this.startTime = startTime;
this.endTime = endTime;
- this.timedOut = timedOut;
+ this.aborted = aborted;
}
- public boolean isTimedOut() {
- return timedOut;
+ public boolean isAborted() {
+ return aborted;
}
public double getStartTime() {
@@ -323,8 +282,8 @@
builder.append("endTime: ");
builder.append(endTime);
- if (isTimedOut()) {
- builder.append(", timeout: ");
+ if (isAborted()) {
+ builder.append(", aborted: ");
builder.append(true);
}
@@ -333,25 +292,29 @@
};
protected void assertRequestData(RequestData requestData, String data,
- double startTime, double endTime, boolean timedOut) {
+ 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("Timeout check failed for " + requestData, timedOut, requestData.isTimedOut());
+ assertEquals("Aborted check failed for " + requestData, aborted, requestData.isAborted());
}
protected void ajax(String data, String parameters) {
- scriptCommands.add(new AjaxCommand(data, parameters));
+ page.executeJavaScript("simulationContext.ajax('" + data + "', " + parameters + ");");
}
protected void ajax(String data, ParametersBuilder builder) {
- scriptCommands.add(new AjaxCommand(data, builder.getParamatersString()));
+ ajax(data, builder.getParamatersString());
}
+ protected void executeAfterDelay(String expression) {
+ page.executeJavaScript("simulationContext.executeAfterDelay(function(){" + expression + "});");
+ }
+
protected void delay(int delayValue) {
- scriptCommands.add(new DelayCommand(delayValue));
+ page.executeJavaScript("simulationContext.wait(" + delayValue + ");");
}
protected String getRootContextPath() {
@@ -382,15 +345,11 @@
at.apply(facesContext, root);
}
- @Override
- protected HtmlPage renderView() throws Exception {
- StringBuilder builder = new StringBuilder("<script type='text/javascript'>" +
- "window.simulationContext = new SimulationContext(" + AJAX_SUBMIT + ");" +
- "do { with (simulationContext) {");
- for (ScriptCommand command : scriptCommands) {
- command.append(builder);
- }
- builder.append("}; Timer.execute(); } while (!Timer.isEmpty());</script>");
+ 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);
@@ -398,27 +357,56 @@
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 super.renderView();
+ return this.page;
}
- protected TestsResult getTestsResult(HtmlPage 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 = (String) object.get("data", object);
+ 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 timedOut = object.get("timedOut", object);
- boolean timedOutBoolean = timedOut instanceof Boolean && (Boolean) timedOut;
+ Object aborted = object.get("aborted", object);
+ boolean abortedBoolean = aborted instanceof Boolean && (Boolean) aborted;
- result.addData(new RequestData(data, startTime, endTime, timedOutBoolean));
+ result.addData(new RequestData(data, startTime, endTime, abortedBoolean));
}
scriptResult = page.executeJavaScript("Timer.currentTime");
@@ -428,9 +416,11 @@
}
@Override
- protected WebClient createWebClient() {
- WebClient webClient = super.createWebClient();
+ 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) {
@@ -438,8 +428,51 @@
}
});
+ }
+}
+
+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();
- return webClient;
+ 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;
+ }
+
+ }
}
Added: trunk/sandbox/ui/queue/src/test/java/org/richfaces/AjaxFormQueuesTest.java
===================================================================
--- trunk/sandbox/ui/queue/src/test/java/org/richfaces/AjaxFormQueuesTest.java (rev 0)
+++ trunk/sandbox/ui/queue/src/test/java/org/richfaces/AjaxFormQueuesTest.java 2008-11-19 16:21:37 UTC (rev 11238)
@@ -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.richfaces;
+
+
+
+/**
+ * @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");
+ }
+}
Added: trunk/sandbox/ui/queue/src/test/java/org/richfaces/ImplicitQueuesTest.java
===================================================================
--- trunk/sandbox/ui/queue/src/test/java/org/richfaces/ImplicitQueuesTest.java (rev 0)
+++ trunk/sandbox/ui/queue/src/test/java/org/richfaces/ImplicitQueuesTest.java 2008-11-19 16:21:37 UTC (rev 11238)
@@ -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.richfaces;
+
+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);
+ }
+}
Added: trunk/sandbox/ui/queue/src/test/java/org/richfaces/QueueDiscoveryTest.java
===================================================================
--- trunk/sandbox/ui/queue/src/test/java/org/richfaces/QueueDiscoveryTest.java (rev 0)
+++ trunk/sandbox/ui/queue/src/test/java/org/richfaces/QueueDiscoveryTest.java 2008-11-19 16:21:37 UTC (rev 11238)
@@ -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.richfaces;
+
+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));
+ }
+
+}
Modified: trunk/sandbox/ui/queue/src/test/java/org/richfaces/ScriptTest.java
===================================================================
--- trunk/sandbox/ui/queue/src/test/java/org/richfaces/ScriptTest.java 2008-11-19 16:12:10 UTC (rev 11237)
+++ trunk/sandbox/ui/queue/src/test/java/org/richfaces/ScriptTest.java 2008-11-19 16:21:37 UTC (rev 11238)
@@ -24,38 +24,28 @@
import java.util.List;
-import com.gargoylesoftware.htmlunit.html.HtmlPage;
-
/**
- * @author mikalaj
- *
+ * @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);
}
- @Override
- public void setUp() throws Exception {
- super.setUp();
-
- buildView("/script.xhtml");
- }
-
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- }
-
public void testSimpleAjax() throws Exception {
+ renderView(VIEW_NAME);
+
delay(50);
ajax("a", createAjaxParameters().requestTime(100));
ajax("b", createAjaxParameters().requestTime(150));
- TestsResult result = getTestsResult(renderView());
+ TestsResult result = getTestsResult();
List<RequestData> dataList = result.getDataList();
assertEquals(2, dataList.size());
assertRequestData(dataList.get(0), "a", 50, 150, false);
@@ -65,13 +55,15 @@
}
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(renderView());
+ TestsResult result = getTestsResult();
List<RequestData> dataList = result.getDataList();
assertEquals(2, dataList.size());
assertRequestData(dataList.get(0), "a", 50, 550, false);
@@ -81,20 +73,20 @@
}
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'}");
-
- HtmlPage page = this.renderView();
- assertNotNull(page);
-
- System.out.println(getTestsResult(page));
+ System.out.println(getTestsResult());
}
public void testImplicitQueue() throws Exception {
+ renderView(VIEW_NAME);
+
ParametersBuilder parameters = createAjaxParameters().
requestDelay(100).
implicitEventsQueue("myqueue").
@@ -106,7 +98,7 @@
delay(10);
ajax("c", parameters.requestDelay(50));
- TestsResult result = getTestsResult(this.renderView());
+ TestsResult result = getTestsResult();
List<RequestData> dataList = result.getDataList();
assertEquals(1, dataList.size());
Added: trunk/sandbox/ui/queue/src/test/resources/org/richfaces/ajax-form.xhtml
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/richfaces/ajax-form.xhtml (rev 0)
+++ trunk/sandbox/ui/queue/src/test/resources/org/richfaces/ajax-form.xhtml 2008-11-19 16:21:37 UTC (rev 11238)
@@ -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>
Added: trunk/sandbox/ui/queue/src/test/resources/org/richfaces/disabled.xhtml
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/richfaces/disabled.xhtml (rev 0)
+++ trunk/sandbox/ui/queue/src/test/resources/org/richfaces/disabled.xhtml 2008-11-19 16:21:37 UTC (rev 11238)
@@ -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>
Added: trunk/sandbox/ui/queue/src/test/resources/org/richfaces/discovery-base.xhtml
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/richfaces/discovery-base.xhtml (rev 0)
+++ trunk/sandbox/ui/queue/src/test/resources/org/richfaces/discovery-base.xhtml 2008-11-19 16:21:37 UTC (rev 11238)
@@ -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>
Added: trunk/sandbox/ui/queue/src/test/resources/org/richfaces/global-both.xhtml
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/richfaces/global-both.xhtml (rev 0)
+++ trunk/sandbox/ui/queue/src/test/resources/org/richfaces/global-both.xhtml 2008-11-19 16:21:37 UTC (rev 11238)
@@ -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>
Added: trunk/sandbox/ui/queue/src/test/resources/org/richfaces/global-form.xhtml
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/richfaces/global-form.xhtml (rev 0)
+++ trunk/sandbox/ui/queue/src/test/resources/org/richfaces/global-form.xhtml 2008-11-19 16:21:37 UTC (rev 11238)
@@ -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>
Added: trunk/sandbox/ui/queue/src/test/resources/org/richfaces/global-view.xhtml
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/richfaces/global-view.xhtml (rev 0)
+++ trunk/sandbox/ui/queue/src/test/resources/org/richfaces/global-view.xhtml 2008-11-19 16:21:37 UTC (rev 11238)
@@ -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>
Added: trunk/sandbox/ui/queue/src/test/resources/org/richfaces/implicit-global-queue.xhtml
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/richfaces/implicit-global-queue.xhtml (rev 0)
+++ trunk/sandbox/ui/queue/src/test/resources/org/richfaces/implicit-global-queue.xhtml 2008-11-19 16:21:37 UTC (rev 11238)
@@ -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>
Added: trunk/sandbox/ui/queue/src/test/resources/org/richfaces/legacy.xhtml
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/richfaces/legacy.xhtml (rev 0)
+++ trunk/sandbox/ui/queue/src/test/resources/org/richfaces/legacy.xhtml 2008-11-19 16:21:37 UTC (rev 11238)
@@ -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>
Modified: trunk/sandbox/ui/queue/src/test/resources/org/richfaces/simulation.js
===================================================================
--- trunk/sandbox/ui/queue/src/test/resources/org/richfaces/simulation.js 2008-11-19 16:12:10 UTC (rev 11237)
+++ trunk/sandbox/ui/queue/src/test/resources/org/richfaces/simulation.js 2008-11-19 16:21:37 UTC (rev 11238)
@@ -85,38 +85,89 @@
}, this.time);
};
+SimulationContext.prototype.executeAfterDelay = function(code) {
+ Timer.addEventToTimer(function() {
+ code();
+ }, this.time);
+};
+
window.simulationContext = undefined;
-A4J.AJAX.SubmitQuery = function(query, options) {
- var request = {};
+window.XMLHttpRequest = function() {
+ this.requestTime = XMLHttpRequest.requestTime || 0;
+ this.data = XMLHttpRequest.data;
+
+ this.responseText = null;
+ this.responseXML = null;
+
+ this.readyState = 0;
+}
- var length = window.simulationContext.results.push({data: options.data, startTime: Timer.currentTime});
-
- var timer = Timer.addEventToTimer(function() {
- if (request.timeoutTimer) {
- Timer.removeEventFromTimer(request.timeoutTimer);
- }
+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 />";
- if (request.queue) {
- request.queue.pop();
- }
+ 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);
+};
- window.simulationContext.results[length - 1].endTime = Timer.currentTime;
+XMLHttpRequest.prototype.setRequestHeader = function(name, value) {
- }, 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);
+};
+
+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;
}
+}
- return request;
-}
-
17 years, 6 months
JBoss Rich Faces SVN: r11237 - trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng.
by richfaces-svn-commits@lists.jboss.org
Author: dsvyatobatsko
Date: 2008-11-19 11:12:10 -0500 (Wed, 19 Nov 2008)
New Revision: 11237
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeTest.java
Log:
https://jira.jboss.org/jira/browse/RF-4820
https://jira.jboss.org/jira/browse/RF-4821
Modified: trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeTest.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeTest.java 2008-11-19 14:31:29 UTC (rev 11236)
+++ trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeTest.java 2008-11-19 16:12:10 UTC (rev 11237)
@@ -42,6 +42,7 @@
tester.reset();
tester.setupControl(TestSetupEntry.ajaxSingle, Boolean.TRUE);
tester.clickLoad();
+ //navigate to the first child
String compId = getAutoTester(this).getClientId(AutoTester.COMPONENT_ID);
clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/table[1]/tbody/tr/td/div/a");
clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/div/table[1]/tbody/tr/td/div/a");
@@ -61,9 +62,11 @@
tester.reset();
tester.setupControl(TestSetupEntry.ajaxSingle, Boolean.TRUE);
tester.clickLoad();
+ writeStatus("Navigate to the first child");
String compId = getAutoTester(this).getClientId(AutoTester.COMPONENT_ID);
clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/table[1]/tbody/tr/td/div/a");
clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/div/table[1]/tbody/tr/td/div/a");
+ writeStatus("Set a new invalid value for the child");
type("//*[@id='"+ compId + ":childs']/div/div/table[1]/tbody/tr/td[3]/input", "");
tester.startTracing();
writeStatus("Test ajaxSingle attribute in case of invalid component state");
@@ -72,6 +75,49 @@
tester.checkNodeExpandedListener(false);
}
+ @Test
+ public void testImmediate(Template template) {
+ AutoTester tester = getAutoTester(this);
+ tester.renderPage(template, null);
+ tester.reset();
+ tester.setupControl(TestSetupEntry.immediate, Boolean.TRUE);
+ tester.clickLoad();
+ writeStatus("Navigate to the first child");
+ String compId = getAutoTester(this).getClientId(AutoTester.COMPONENT_ID);
+ clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/table[1]/tbody/tr/td/div/a");
+ clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/div/table[1]/tbody/tr/td/div/a");
+ writeStatus("Set a new value for the child");
+ type("//*[@id='"+ compId + ":childs']/div/div/table[1]/tbody/tr/td[3]/input", "New");
+ tester.startTracing();
+ writeStatus("Test immediate attribute");
+ clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/div/table[1]/tbody/tr/td/div/a");
+ tester.checkUpdateModel(true);
+ tester.checkNodeExpandedListener(true);
+ }
+
+ @Test
+ public void testImmediateWithExternalValidationFailed(Template template) {
+ AutoTester tester = getAutoTester(this);
+ tester.renderPage(template, null);
+ tester.reset();
+ tester.setupControl(TestSetupEntry.immediate, Boolean.TRUE);
+ tester.clickLoad();
+ tester.startTracing();
+ writeStatus("Navigate to the first child");
+ String compId = getAutoTester(this).getClientId(AutoTester.COMPONENT_ID);
+ clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/table[1]/tbody/tr/td/div/a");
+ clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/div/table[1]/tbody/tr/td/div/a");
+ writeStatus("set a new value for the child");
+ type("//*[@id='"+ compId + ":childs']/div/div/table[1]/tbody/tr/td[3]/input", "New");
+ writeStatus("Set external validation to fail");
+ tester.setExtrenalValidationFailed();
+ tester.startTracing();
+ writeStatus("Test immediate attribute with external validation failed");
+ clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/div/table[1]/tbody/tr/td/div/a");
+ tester.checkUpdateModel(false);
+ tester.checkNodeExpandedListener(true);
+ }
+
@Override
public void sendAjax() {
AutoTester tester = getAutoTester(this);
@@ -89,4 +135,5 @@
public String getAutoTestUrl() {
return "pages/tree/treeAutoTest.xhtml";
}
+
}
17 years, 6 months
JBoss Rich Faces SVN: r11236 - trunk/sandbox/samples/queue-sample/src/main/webapp/pages.
by richfaces-svn-commits@lists.jboss.org
Author: dmorozov
Date: 2008-11-19 09:31:29 -0500 (Wed, 19 Nov 2008)
New Revision: 11236
Modified:
trunk/sandbox/samples/queue-sample/src/main/webapp/pages/events.xhtml
Log:
https://jira.jboss.org/jira/browse/RF-4899
Modified: trunk/sandbox/samples/queue-sample/src/main/webapp/pages/events.xhtml
===================================================================
--- trunk/sandbox/samples/queue-sample/src/main/webapp/pages/events.xhtml 2008-11-19 14:11:12 UTC (rev 11235)
+++ trunk/sandbox/samples/queue-sample/src/main/webapp/pages/events.xhtml 2008-11-19 14:31:29 UTC (rev 11236)
@@ -91,10 +91,13 @@
<a4j:commandLink onclick="resetCells()" value="Oncomplete component client handler" eventsQueue="queue"
onbeforedomupdate="request.options.oncomplete = handlers['component:oncomplete']" data="data" />
- <a4j:commandLink onclick="resetCells(); A4J.AJAX.onError = undefined;" value="Onerror" eventsQueue="queue" timeout="1" data="data" />
+ <a4j:commandLink onclick="resetCells(); A4J.AJAX.onError = undefined;" value="Queue only onerror" eventsQueue="queue" timeout="1" data="data"
+ oncomplete="handlers['component:oncomplete'](request, event, data)"
+ onbeforedomupdate="handlers['component:onbeforedomupdate'](request, event, data)" />
- <a4j:commandLink onclick="resetCells(); A4J.AJAX.onError = handlers['component:onerror'];" value="Component onerror" eventsQueue="queue"
- timeout="1" data="data" />
+ <a4j:commandLink onclick="resetCells(); A4J.AJAX.onError = handlers['component:onerror'];" value="Component and queue onerror" eventsQueue="queue"
+ oncomplete="handlers['component:oncomplete'](request, event, data)"
+ onbeforedomupdate="handlers['component:onbeforedomupdate'](request, event, data)" timeout="1" data="data" />
<a4j:commandLink onclick="resetCells()" value="Both component handlers" eventsQueue="queue"
oncomplete="handlers['component:oncomplete'](request, event, data)"
@@ -107,10 +110,13 @@
<a4j:commandLink onclick="resetCells()" value="Oncomplete component client handler"
onbeforedomupdate="request.options.oncomplete = handlers['component:oncomplete']" data="data" />
- <a4j:commandLink onclick="resetCells(); A4J.AJAX.onError = undefined;" value="Onerror" timeout="1" data="data" />
+ <a4j:commandLink onclick="resetCells(); A4J.AJAX.onError = undefined;" value="Queue only onerror" timeout="1" data="data"
+ oncomplete="handlers['component:oncomplete'](request, event, data)"
+ onbeforedomupdate="handlers['component:onbeforedomupdate'](request, event, data)" />
- <a4j:commandLink onclick="resetCells(); A4J.AJAX.onError = handlers['component:onerror'];" value="Component onerror"
- timeout="1" data="data" />
+ <a4j:commandLink onclick="resetCells(); A4J.AJAX.onError = handlers['component:onerror'];" value="Component and queue onerror"
+ oncomplete="handlers['component:oncomplete'](request, event, data)"
+ onbeforedomupdate="handlers['component:onbeforedomupdate'](request, event, data)" timeout="1" data="data" />
<a4j:commandLink onclick="resetCells()" value="Both component handlers"
oncomplete="handlers['component:oncomplete'](request, event, data)"
17 years, 6 months
JBoss Rich Faces SVN: r11235 - trunk/sandbox/samples/queue-sample/src/main/webapp/pages.
by richfaces-svn-commits@lists.jboss.org
Author: dmorozov
Date: 2008-11-19 09:11:12 -0500 (Wed, 19 Nov 2008)
New Revision: 11235
Modified:
trunk/sandbox/samples/queue-sample/src/main/webapp/pages/events.xhtml
Log:
https://jira.jboss.org/jira/browse/RF-4899
Modified: trunk/sandbox/samples/queue-sample/src/main/webapp/pages/events.xhtml
===================================================================
--- trunk/sandbox/samples/queue-sample/src/main/webapp/pages/events.xhtml 2008-11-19 14:09:05 UTC (rev 11234)
+++ trunk/sandbox/samples/queue-sample/src/main/webapp/pages/events.xhtml 2008-11-19 14:11:12 UTC (rev 11235)
@@ -10,7 +10,7 @@
<body>
<f:view>
<ui:include src="/templates/navigation.xhtml" />
-
+
<a4j:status startText="...running..." startStyle="color: green" />
<style type="text/css">
@@ -60,51 +60,61 @@
resetCells();
- var handlersList = ["onbeforedomupdate", "onsubmit", "oncomplete", "onerror"];
+ var events = {
+ "onbeforedomupdate": ["request", "event", "data"],
+ "onsubmit": ["request"],
+ "oncomplete": ["request", "event", "data"],
+ "onerror": ["request", "status", "message"]
+ };
+
+ var handlers = {};
- var handlers = {};
+ for (var handlerName in events) {
+ var args = events[handlerName];
+ var argCheck = "";
+ for ( var i = 0; i < args.length; i++) {
+ argCheck += "if (!" + args[i] + ") alert('argument " + args[i] + " missing for handler " + handlerName + "');";
+ }
- for ( var i = 0; i < handlersList.length; i++) {
- var handlerName = handlersList[i];
- handlers["queue:" + handlerName] = new Function("my$('" + handlerName + "Elt').innerHTML += 'Q'");
- handlers["component:" + handlerName] = new Function("my$('" + handlerName + "Elt').innerHTML += 'C'");
+ handlers["queue:" + handlerName] = Function.constructor.apply(this, [args, argCheck + "my$('" + handlerName + "Elt').innerHTML += 'Q'"]);
+ handlers["component:" + handlerName] = Function.constructor.apply(this, [args, argCheck + "my$('" + handlerName + "Elt').innerHTML += 'C'"]);
}
//]]></script>
- <q:queue name="queue" onsubmit="handlers['queue:onsubmit']()" onerror="handlers['queue:onerror']()"
- oncomplete="handlers['queue:oncomplete']()" onbeforedomupdate="handlers['queue:onbeforedomupdate']()" />
+ <q:queue name="queue" onsubmit="handlers['queue:onsubmit'](request)" onerror="handlers['queue:onerror'](request, status, message)"
+ oncomplete="handlers['queue:oncomplete'](request, event, data)" onbeforedomupdate="handlers['queue:onbeforedomupdate'](request, event, data)" />
<h:form>
<h:panelGrid columns="1">
Components in queue
- <a4j:commandLink onclick="resetCells()" value="No component handlers" eventsQueue="queue"/>
+ <a4j:commandLink onclick="resetCells()" value="No component handlers" eventsQueue="queue" data="data" />
<a4j:commandLink onclick="resetCells()" value="Oncomplete component client handler" eventsQueue="queue"
- onbeforedomupdate="request.options.oncomplete = handlers['component:oncomplete']" />
+ onbeforedomupdate="request.options.oncomplete = handlers['component:oncomplete']" data="data" />
- <a4j:commandLink onclick="resetCells(); A4J.AJAX.onError = undefined;" value="Onerror" eventsQueue="queue" timeout="1" />
+ <a4j:commandLink onclick="resetCells(); A4J.AJAX.onError = undefined;" value="Onerror" eventsQueue="queue" timeout="1" data="data" />
<a4j:commandLink onclick="resetCells(); A4J.AJAX.onError = handlers['component:onerror'];" value="Component onerror" eventsQueue="queue"
- timeout="1" />
+ timeout="1" data="data" />
<a4j:commandLink onclick="resetCells()" value="Both component handlers" eventsQueue="queue"
- oncomplete="handlers['component:oncomplete']()"
- onbeforedomupdate="handlers['component:onbeforedomupdate']()" />
+ oncomplete="handlers['component:oncomplete'](request, event, data)"
+ onbeforedomupdate="handlers['component:onbeforedomupdate'](request, event, data)" data="data" />
</h:panelGrid>
<h:panelGrid columns="1">
Components without queue
- <a4j:commandLink onclick="resetCells()" value="No component handlers" />
+ <a4j:commandLink onclick="resetCells()" value="No component handlers" data="data" />
<a4j:commandLink onclick="resetCells()" value="Oncomplete component client handler"
- onbeforedomupdate="request.options.oncomplete = handlers['component:oncomplete']" />
+ onbeforedomupdate="request.options.oncomplete = handlers['component:oncomplete']" data="data" />
- <a4j:commandLink onclick="resetCells(); A4J.AJAX.onError = undefined;" value="Onerror" timeout="1" />
+ <a4j:commandLink onclick="resetCells(); A4J.AJAX.onError = undefined;" value="Onerror" timeout="1" data="data" />
<a4j:commandLink onclick="resetCells(); A4J.AJAX.onError = handlers['component:onerror'];" value="Component onerror"
- timeout="1" />
+ timeout="1" data="data" />
<a4j:commandLink onclick="resetCells()" value="Both component handlers"
- oncomplete="handlers['component:oncomplete']()"
- onbeforedomupdate="handlers['component:onbeforedomupdate']()" />
+ oncomplete="handlers['component:oncomplete'](request, event, data)"
+ onbeforedomupdate="handlers['component:onbeforedomupdate'](request, event, data)" data="data" />
</h:panelGrid>
</h:form>
</f:view>
17 years, 6 months
JBoss Rich Faces SVN: r11234 - trunk/framework/impl/src/main/javascript/ajaxjsf.
by richfaces-svn-commits@lists.jboss.org
Author: dmorozov
Date: 2008-11-19 09:09:05 -0500 (Wed, 19 Nov 2008)
New Revision: 11234
Modified:
trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
Log:
https://jira.jboss.org/jira/browse/RF-4899
Modified: trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
===================================================================
--- trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2008-11-19 13:23:40 UTC (rev 11233)
+++ trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2008-11-19 14:09:05 UTC (rev 11234)
@@ -783,8 +783,8 @@
var _onerror = req._onerror;
if (_onerror) {
req._onerror = function() {
- _queueonerror.call(arguments);
- _onerror.call(arguments);
+ _queueonerror.apply(this, arguments);
+ _onerror.apply(this, arguments);
};
} else {
req._onerror = _queueonerror;
17 years, 6 months
JBoss Rich Faces SVN: r11233 - trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng.
by richfaces-svn-commits@lists.jboss.org
Author: konstantin.mishin
Date: 2008-11-19 08:23:40 -0500 (Wed, 19 Nov 2008)
New Revision: 11233
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/OrderingListTest.java
Log:
RF-4942
Modified: trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/OrderingListTest.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/OrderingListTest.java 2008-11-19 12:52:43 UTC (rev 11232)
+++ trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/OrderingListTest.java 2008-11-19 13:23:40 UTC (rev 11233)
@@ -83,6 +83,21 @@
private String immediateId;
/**
+ * respective number of columns created; header dimensions are ok
+ */
+ @Test
+ public void testNumberOfColumnsAndHeaderDimensions(Template template) {
+ renderPage(template, initMethod);
+ initFields();
+ String tdXpath = "id('" + orderingListId +"tbody')/tr[1]/td";
+ String thXpath = "id('" + orderingListId +"internal_header_tab')/thead/tr/th";
+ Assert.assertEquals(selenium.getXpathCount(tdXpath).intValue(), 3);
+ for (int i = 1; i <= 3; i++) {
+ Assert.assertEquals(selenium.getElementWidth("xpath=" + tdXpath + "[" + i + "]").intValue(), selenium.getElementWidth("xpath=" + thXpath + "[" + i + "]").intValue());
+ }
+ }
+
+ /**
* value updated, listener fire
*/
@Test
@@ -190,9 +205,9 @@
public void testValue(Template template) {
renderPage(template, initMethod);
initFields();
- int count = selenium.getXpathCount("xpath=id('" + orderingListId +"tbody')/tr").intValue();
+ int count = selenium.getXpathCount("id('" + orderingListId +"tbody')/tr").intValue();
for (int i = 0; i < count; i++) {
- Assert.assertEquals(selenium.getText("xpath=id('" + orderingListId +"tbody')/tr[" + (i + 1) + "]td[1]"), "item" + i);
+ Assert.assertEquals(selenium.getText("xpath=id('" + orderingListId +"tbody')/tr[" + (i + 1) + "]/td[1]"), "item" + i);
}
}
17 years, 6 months
JBoss Rich Faces SVN: r11231 - trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/html/images.
by richfaces-svn-commits@lists.jboss.org
Author: alevkovsky
Date: 2008-11-19 07:50:36 -0500 (Wed, 19 Nov 2008)
New Revision: 11231
Modified:
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/html/images/EditorAdvancedThemeIcons.java
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/html/images/EditorIcons.java
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/html/images/EditorSimpleThemeIcons.java
Log:
Editor: adjust icons drawing
Modified: trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/html/images/EditorAdvancedThemeIcons.java
===================================================================
--- trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/html/images/EditorAdvancedThemeIcons.java 2008-11-19 10:07:23 UTC (rev 11230)
+++ trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/html/images/EditorAdvancedThemeIcons.java 2008-11-19 12:50:36 UTC (rev 11231)
@@ -64,10 +64,10 @@
public void paint(ResourceContext context, Graphics2D graphics) {
Object[] stored = (Object[]) restoreData(context);
if (stored != null) {
- BufferedImage block1 = paintMainBlock(stored, false);
+ BufferedImage block1 = paintMainBlock(stored, false, false);
BufferedImage separator = paintSeparatorBlock(stored);
- BufferedImage block2 = paintMainBlock(stored, true);
- BufferedImage block3 = paintMainBlock(stored, true);
+ BufferedImage block2 = paintMainBlock(stored, true, false);
+ BufferedImage block3 = paintMainBlock(stored, true, true);
BufferedImage firstTriangle1 = paintFirstTriangleBlock(stored, false);
BufferedImage firstTriangle2 = paintFirstTriangleBlock(stored, true);
@@ -78,6 +78,7 @@
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+
graphics.drawImage(block1, 0, 0, 22, 22, null);
graphics.drawImage(separator, 22, 0, 5, 22, null);
graphics.drawImage(block2, 0, 22, 22, 22, null);
Modified: trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/html/images/EditorIcons.java
===================================================================
--- trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/html/images/EditorIcons.java 2008-11-19 10:07:23 UTC (rev 11230)
+++ trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/html/images/EditorIcons.java 2008-11-19 12:50:36 UTC (rev 11231)
@@ -26,6 +26,7 @@
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.RenderingHints;
+import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.util.Date;
@@ -51,7 +52,7 @@
private final String PANEL_BORDER_COLOR = "panelBorderColor";
private final String GENERAL_TEXT_COLOR = "generalTextColor";
- private final int SUB_BORDER_TRANSPARENCY = 100;
+ private final int SUB_BORDER_TRANSPARENCY = 150;
public EditorIcons() {
super();
@@ -105,7 +106,7 @@
}
- protected BufferedImage paintMainBlock(Object[] colors, boolean selected) {
+ protected BufferedImage paintMainBlock(Object[] colors, boolean selected, boolean withoutSubBorders) {
int w = 22;
int h = 22;
@@ -128,11 +129,7 @@
} else {
contentColor = additionalBackgroundColor;
}
- Paint gradient1 = new GradientPaint(w, h - 1, contentColor, 0, 1,
- Color.white);
- g2d.setPaint(gradient1);
- Rectangle2D border = new Rectangle2D.Double(0, 1, w, h - 1);
- g2d.fill(border);
+ fillBodyWithGradient(g2d, w, h, contentColor);
// Draw Border
g2d.setColor(panelBorderColor);
@@ -140,11 +137,15 @@
g2d.drawLine(0, h - 1, w, h - 1);
// Draw subBorder
- g2d.setColor(subBorderColorWithAlpha);
- g2d.drawLine(0, 1, 0, h - 2);
- g2d.drawLine(0, 1, w - 1, 1);
- g2d.drawLine(w - 1, 1, w - 1, h - 2);
- g2d.drawLine(0, h - 2, w - 1, h - 2);
+ Color subBorderColorWithAlpha2 = new Color(contentColor.getRed(), contentColor.getGreen(), contentColor.getBlue(), SUB_BORDER_TRANSPARENCY);
+ if(!withoutSubBorders){
+ g2d.setColor(subBorderColorWithAlpha);
+ g2d.drawLine(0, 1, 0, h - 2);
+ g2d.drawLine(0, 1, w - 1, 1);
+ g2d.setColor(subBorderColorWithAlpha2);
+ g2d.drawLine(0, h - 2, w - 1, h - 2);
+ g2d.drawLine(w-1, 1, w-1, h - 2);
+ }
g2d.dispose();
@@ -177,8 +178,7 @@
return image;
}
- protected BufferedImage paintFirstTriangleBlock(Object[] colors,
- boolean selected) {
+ protected BufferedImage paintFirstTriangleBlock(Object[] colors, boolean selected) {
int w = 11;
int h = 22;
@@ -194,19 +194,18 @@
Color generalTextColor = (Color) colors[3];
Color subBorderColorWithAlpha = new Color(255, 255, 255,
SUB_BORDER_TRANSPARENCY);
+
// Draw body
Color contentColor;
if (selected) {
contentColor = selectControlColor;
+
} else {
contentColor = additionalBackgroundColor;
}
- Paint gradient1 = new GradientPaint(w, h - 1, contentColor, 0, 1,
- Color.white);
- g2d.setPaint(gradient1);
- Rectangle2D border = new Rectangle2D.Double(0, 1, w, h - 1);
- g2d.fill(border);
+ Color subBorderColorWithAlpha2 = new Color(contentColor.getRed(), contentColor.getGreen(), contentColor.getBlue(), SUB_BORDER_TRANSPARENCY);
+ fillBodyWithGradient(g2d, w, h, contentColor);
// Draw Border
g2d.setColor(panelBorderColor);
@@ -215,10 +214,14 @@
// Draw body
g2d.setColor(subBorderColorWithAlpha);
- g2d.drawLine(0, 1, 0, h - 2);
- g2d.drawLine(0, 1, w - 1, 1);
- g2d.drawLine(w - 1, 1, w - 1, h - 2);
+
+ g2d.drawLine(0, 1, 0, h - 2);
+ g2d.drawLine(0, 1, w - 1, 1);
+
+ g2d.setColor(subBorderColorWithAlpha2);
+ g2d.drawLine(w - 1, 1, w - 1, h - 2);
g2d.drawLine(0, h - 2, w - 1, h - 2);
+
paintTriangle(g2d, 3, 10, generalTextColor, Color.WHITE, true);
@@ -241,8 +244,7 @@
}
- protected BufferedImage paintSecondTriangleBlock(Object[] colors,
- boolean selected) {
+ protected BufferedImage paintSecondTriangleBlock(Object[] colors, boolean selected) {
int w = 14;
int h = 22;
@@ -260,22 +262,15 @@
SUB_BORDER_TRANSPARENCY);
// Draw body
- Paint gradient1;
+
Color contentColor;
if (selected) {
contentColor = selectControlColor;
- gradient1 = new GradientPaint(w - 2, h - 2, contentColor, 2, 2,
- Color.white);
} else {
contentColor = additionalBackgroundColor;
- gradient1 = new GradientPaint(w, h - 1, contentColor, 0, 1,
- Color.white);
}
+ fillBodyWithGradient(g2d, w, h, contentColor);
- g2d.setPaint(gradient1);
- Rectangle2D border = new Rectangle2D.Double(1, 1, w - 1, h - 1);
- g2d.fill(border);
-
// Draw Border
g2d.setColor(panelBorderColor);
g2d.drawLine(0, 0, w, 0);
@@ -284,17 +279,50 @@
g2d.drawLine(w - 1, 0, w - 1, h);
// Draw subBorder
- g2d.setColor(subBorderColorWithAlpha);
- g2d.drawLine(1, 1, 1, h - 2);
- g2d.drawLine(1, 1, w - 2, 1);
- g2d.drawLine(w - 2, 1, w - 2, h - 2);
+ if(selected){
+ g2d.setColor(Color.white);
+ }else{
+ g2d.setColor(subBorderColorWithAlpha);
+ }
+ if(selected){
+ g2d.drawLine(1, 1, 1, h - 2);
+ g2d.drawLine(w - 2, 1, w - 2, h - 2);
+ }
+ g2d.drawLine(1, 1, w - 2, 1);
g2d.drawLine(1, h - 2, w - 2, h - 2);
paintTriangle(g2d, 4, 10, generalTextColor, Color.WHITE, true);
return image;
}
+
+ private void fillBodyWithGradient(Graphics2D g2d, int w, int h, Color color) {
+ Color halfColor = new Color(color.getRed(), color.getGreen(), color
+ .getBlue(), 90);
+ Color halfColor2 = new Color(color.getRed(), color.getGreen(), color
+ .getBlue(), 255);
+ Rectangle2D border = new Rectangle2D.Double(0, 0, w, h);
+ g2d.setColor(Color.WHITE);
+ g2d.fill(border);
+
+ g2d.setColor(halfColor);
+ border = new Rectangle2D.Double(0, 0, w, h * 0.4);
+ g2d.fill(border);
+
+ Point2D point2 = new Point2D.Double(w * 0.5, h * 0.4);
+ Point2D point3 = new Point2D.Double(w * 0.5, h);
+
+ border = new Rectangle2D.Double(0, h * 0.4, w, h);
+
+ Paint gradient = new GradientPaint(point2, halfColor2, point3,
+ halfColor);
+ g2d.setPaint(gradient);
+
+ g2d.fill(border);
+
+ }
+
private Graphics2D prepareImage(BufferedImage image) {
Graphics2D g2d = image.createGraphics();
Modified: trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/html/images/EditorSimpleThemeIcons.java
===================================================================
--- trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/html/images/EditorSimpleThemeIcons.java 2008-11-19 10:07:23 UTC (rev 11230)
+++ trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/html/images/EditorSimpleThemeIcons.java 2008-11-19 12:50:36 UTC (rev 11231)
@@ -64,10 +64,10 @@
public void paint(ResourceContext context, Graphics2D graphics) {
Object[] stored = (Object[]) restoreData(context);
if (stored != null) {
- BufferedImage block1 = paintMainBlock(stored, false);
+ BufferedImage block1 = paintMainBlock(stored, false, false);
BufferedImage separator = paintSeparatorBlock(stored);
- BufferedImage block2 = paintMainBlock(stored, true);
- BufferedImage block3 = paintMainBlock(stored, true);
+ BufferedImage block2 = paintMainBlock(stored, true, false);
+ BufferedImage block3 = paintMainBlock(stored, true, true);
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
17 years, 6 months