Author: nbelaevski
Date: 2008-11-24 14:34:21 -0500 (Mon, 24 Nov 2008)
New Revision: 11336
Added:
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRendererData.java
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScript.java
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScriptResourceRenderer.java
Removed:
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRegistry.java
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRendererData.java
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScript.java
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScriptResourceRenderer.java
Modified:
trunk/ui/core/pom.xml
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRenderer.java
trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueRendererTest.java
Log:
https://jira.jboss.org/jira/browse/RF-4957
https://jira.jboss.org/jira/browse/RF-5049
Modified: trunk/ui/core/pom.xml
===================================================================
--- trunk/ui/core/pom.xml 2008-11-24 19:33:30 UTC (rev 11335)
+++ trunk/ui/core/pom.xml 2008-11-24 19:34:21 UTC (rev 11336)
@@ -40,16 +40,6 @@
</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>
Deleted: trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRegistry.java
===================================================================
--- trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRegistry.java 2008-11-24
19:33:30 UTC (rev 11335)
+++ trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRegistry.java 2008-11-24
19:34:21 UTC (rev 11336)
@@ -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.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);
- }
-}
Modified: trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRenderer.java
===================================================================
--- trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRenderer.java 2008-11-24
19:33:30 UTC (rev 11335)
+++ trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRenderer.java 2008-11-24
19:34:21 UTC (rev 11336)
@@ -27,6 +27,7 @@
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import org.ajax4jsf.component.QueueRegistry;
import org.ajax4jsf.component.UIQueue;
import org.ajax4jsf.javascript.AjaxScript;
import org.ajax4jsf.javascript.JSFunctionDefinition;
Deleted: trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRendererData.java
===================================================================
---
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRendererData.java 2008-11-24
19:33:30 UTC (rev 11335)
+++
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRendererData.java 2008-11-24
19:34:21 UTC (rev 11336)
@@ -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.ajax4jsf.renderkit.html;
-
-import java.util.LinkedHashMap;
-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 LinkedHashMap<String, Object>();
- }
-
- queueAttributes.put(key, value);
- }
-
- public void addRequestAttribute(String key, Object value) {
- if (requestAttributes == null) {
- requestAttributes = new LinkedHashMap<String, Object>();
- }
-
- requestAttributes.put(key, value);
- }
-
- public Map<String, Object> getQueueAttributes() {
- return queueAttributes;
- }
-
- public Map<String, Object> getRequestAttributes() {
- return requestAttributes;
- }
-}
Added: trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRendererData.java
===================================================================
--- trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRendererData.java
(rev 0)
+++
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRendererData.java 2008-11-24
19:34:21 UTC (rev 11336)
@@ -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.LinkedHashMap;
+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 LinkedHashMap<String, Object>();
+ }
+
+ queueAttributes.put(key, value);
+ }
+
+ public void addRequestAttribute(String key, Object value) {
+ if (requestAttributes == null) {
+ requestAttributes = new LinkedHashMap<String, Object>();
+ }
+
+ requestAttributes.put(key, value);
+ }
+
+ public Map<String, Object> getQueueAttributes() {
+ return queueAttributes;
+ }
+
+ public Map<String, Object> getRequestAttributes() {
+ return requestAttributes;
+ }
+}
Property changes on:
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRendererData.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScript.java
===================================================================
---
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScript.java 2008-11-24
19:33:30 UTC (rev 11335)
+++
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScript.java 2008-11-24
19:34:21 UTC (rev 11336)
@@ -1,52 +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.ajax4jsf.renderkit.html.scripts;
-
-import org.ajax4jsf.resource.InternetResourceBase;
-import org.ajax4jsf.resource.ResourceContext;
-import org.ajax4jsf.resource.ResourceRenderer;
-
-/**
- * @author Nick Belaevski
- * @since 3.3.0
- */
-public class QueueScript extends InternetResourceBase {
-
- private static final ResourceRenderer renderer = new QueueScriptResourceRenderer();
-
- private String key = getClass().getName();
-
- @Override
- public String getKey() {
- return key;
- }
-
- @Override
- public ResourceRenderer getRenderer(ResourceContext resourceContext) {
- return renderer;
- }
-
- @Override
- public boolean isCacheable(ResourceContext resourceContext) {
- return false;
- }
-}
Added: trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScript.java
===================================================================
--- trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScript.java
(rev 0)
+++
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScript.java 2008-11-24
19:34:21 UTC (rev 11336)
@@ -0,0 +1,52 @@
+/**
+ * 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 org.ajax4jsf.resource.InternetResourceBase;
+import org.ajax4jsf.resource.ResourceContext;
+import org.ajax4jsf.resource.ResourceRenderer;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.0
+ */
+public class QueueScript extends InternetResourceBase {
+
+ private static final ResourceRenderer renderer = new QueueScriptResourceRenderer();
+
+ private String key = getClass().getName();
+
+ @Override
+ public String getKey() {
+ return key;
+ }
+
+ @Override
+ public ResourceRenderer getRenderer(ResourceContext resourceContext) {
+ return renderer;
+ }
+
+ @Override
+ public boolean isCacheable(ResourceContext resourceContext) {
+ return false;
+ }
+}
Property changes on:
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScript.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted:
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScriptResourceRenderer.java
===================================================================
---
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScriptResourceRenderer.java 2008-11-24
19:33:30 UTC (rev 11335)
+++
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScriptResourceRenderer.java 2008-11-24
19:34:21 UTC (rev 11336)
@@ -1,159 +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.ajax4jsf.renderkit.html.scripts;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-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 {
-
- //TODO rename?
- public static final String QUEUE_SCRIPT_ID = "richfaces:ajaxqueues";
-
- 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);
- }
- } else {
- context.getExternalContext().log("");
- }
- }
-
- @Override
- public void encode(InternetResource resource, FacesContext context,
- Object data, Map<String, Object> attributes) throws IOException {
-
- Map<String,Object> newAttributes = new LinkedHashMap<String,
Object>(attributes);
- newAttributes.put(HTML.id_ATTRIBUTE,
context.getExternalContext().encodeNamespace(QUEUE_SCRIPT_ID));
-
- doEncode(resource, context, data, newAttributes);
- }
-
- @Override
- public void encode(InternetResource resource, FacesContext context,
- Object data) throws IOException {
-
- doEncode(resource, context, data,
- Collections.singletonMap(HTML.id_ATTRIBUTE,
- (Object) context.getExternalContext().encodeNamespace(QUEUE_SCRIPT_ID)));
- }
-
- @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";
- }
-
-}
Added:
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScriptResourceRenderer.java
===================================================================
---
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScriptResourceRenderer.java
(rev 0)
+++
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScriptResourceRenderer.java 2008-11-24
19:34:21 UTC (rev 11336)
@@ -0,0 +1,144 @@
+/**
+ * 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.LinkedHashMap;
+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.QueueRegistry;
+import org.ajax4jsf.javascript.JSObject;
+import org.ajax4jsf.javascript.ScriptUtils;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+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 {
+
+ public static final String QUEUE_SCRIPT_ID = "org.ajax4jsf.queue_script";
+
+ 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("if (!EventQueue.getQueue(" +
ScriptUtils.toScript(queueName) + ")) { EventQueue.addQueue(", null);
+ writer.writeText(
+ new JSObject("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);
+
+ Map<String, Object> queues = (Map<String, Object>) data;
+ ResponseWriter writer = context.getResponseWriter();
+
+ writer.writeText("with (A4J.AJAX) {", null);
+ for (Entry<String, Object> entry : queues.entrySet()) {
+ encodeQueue(writer, entry.getKey(), (QueueRendererData) entry.getValue());
+ }
+ writer.writeText("};", null);
+ }
+
+ protected void doEncode(InternetResource resource, FacesContext context,
+ Object data, Map<String, Object> attributes) throws IOException {
+
+ ExternalContext externalContext = context.getExternalContext();
+ Map<String, Object> requestMap = externalContext.getRequestMap();
+
+ String resourceKey = resource.getKey();
+ if (requestMap.get(resourceKey) == null) {
+ requestMap.put(resourceKey, Boolean.TRUE);
+
+ Map<String, Object> 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 {
+
+ Map<String,Object> newAttributes = new LinkedHashMap<String,
Object>(attributes);
+ newAttributes.put(HTML.id_ATTRIBUTE,
context.getExternalContext().encodeNamespace(QUEUE_SCRIPT_ID));
+
+ doEncode(resource, context, data, newAttributes);
+ }
+
+ @Override
+ public void encode(InternetResource resource, FacesContext context,
+ Object data) throws IOException {
+
+ doEncode(resource, context, data,
+ Collections.singletonMap(HTML.id_ATTRIBUTE,
+ (Object) context.getExternalContext().encodeNamespace(QUEUE_SCRIPT_ID)));
+ }
+
+ @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";
+ }
+
+}
Property changes on:
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/scripts/QueueScriptResourceRenderer.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueRendererTest.java
===================================================================
--- trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueRendererTest.java 2008-11-24
19:33:30 UTC (rev 11335)
+++ trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueRendererTest.java 2008-11-24
19:34:21 UTC (rev 11336)
@@ -48,10 +48,6 @@
return s.replace(" ", "");
}
- private static final String QUEUE_INIT_PROLOG = "A4J.AJAX.EventQueue.addQueue(new
A4J.AJAX.EventQueue(";
-
- private static final String QUEUE_INIT_PROLOG_DRIED = dry(QUEUE_INIT_PROLOG);
-
/**
* @param name
*/
@@ -86,9 +82,35 @@
private String getQueueScript(HtmlPage page) throws JaxenException {
List<?> list = page.getByXPath("//head/script[@id='" +
QueueScriptResourceRenderer.QUEUE_SCRIPT_ID + "']/text()");
DomText text = (DomText) list.get(0);
- return text.getData();
+ String scriptData = text.getData();
+
+ return scriptData.replaceAll("^\\Qwith (A4J.AJAX) {\\E|\\Q};\\E$",
"");
}
+
+ private String[] splitScript(String s) {
+ String[] split = s.split(";");
+ for (int i = 0; i < split.length; i++) {
+ split[i] = split[i] + ";";
+ }
+
+ return split;
+ }
+
+ private String createQueueInitString(String queueName, String queueParams, String
requestParams) {
+ StringBuilder builder = new StringBuilder("if
(!EventQueue.getQueue('").append(queueName).append("')) {
EventQueue.addQueue(new EventQueue('").
+ append(queueName).append("'");
+ builder.append(",");
+ builder.append(String.valueOf(queueParams));
+
+ builder.append(",");
+ builder.append(String.valueOf(requestParams));
+
+ builder.append(")) };");
+
+ return builder.toString();
+ }
+
public void testViewQueueName() throws Exception {
UIQueue queue = (UIQueue) application.createComponent(UIQueue.COMPONENT_TYPE);
queue.setName("test_view_queue");
@@ -96,7 +118,8 @@
HtmlPage page = renderView();
String queueScript = getQueueScript(page);
- assertTrue(queueScript.startsWith(QUEUE_INIT_PROLOG +
"'test_view_queue'"));
+
+ assertEquals(createQueueInitString("test_view_queue", null, null),
queueScript);
}
public void testViewQueueDefaultName() throws Exception {
@@ -105,7 +128,7 @@
HtmlPage page = renderView();
String queueScript = getQueueScript(page);
- assertTrue(queueScript.startsWith(QUEUE_INIT_PROLOG + "'" +
UIQueue.GLOBAL_QUEUE_NAME + "'"));
+ assertEquals(createQueueInitString(UIQueue.GLOBAL_QUEUE_NAME, null, null),
queueScript);
}
public void testFormQueueName() throws Exception {
@@ -115,7 +138,7 @@
HtmlPage page = renderView();
String queueScript = getQueueScript(page);
- assertTrue(queueScript.startsWith(QUEUE_INIT_PROLOG +
"'theform:test_view_queue'"));
+ assertEquals(createQueueInitString("theform:test_view_queue", null, null),
queueScript);
}
public void testFormQueueDefaultName() throws Exception {
@@ -124,7 +147,7 @@
HtmlPage page = renderView();
String queueScript = getQueueScript(page);
- assertTrue(queueScript.startsWith(QUEUE_INIT_PROLOG + "'theform'"));
+ assertEquals(createQueueInitString("theform", null, null), queueScript);
}
public void testRenderQueueAttributes() throws Exception {
@@ -146,18 +169,17 @@
HtmlPage page = renderView();
String queueScript = dry(getQueueScript(page));
- String[] scripts = queueScript.split(";");
+ String[] scripts = splitScript(queueScript);
assertEquals(3, scripts.length);
- assertEquals(QUEUE_INIT_PROLOG_DRIED +
- "'theform',{'size':10,'sizeExceededBehavior':'dropNext','onsizeexceeded':function(query,options,event){sizeexceeded_handler()}},null))",
+ assertEquals(dry(createQueueInitString("theform",
+ "{'size':10,'sizeExceededBehavior':'dropNext','onsizeexceeded':function(query,options,event){sizeexceeded_handler()}}",
+ null)),
scripts[0]);
- assertEquals(QUEUE_INIT_PROLOG_DRIED +
- "'theform:unsizedQueue',{'size':-1},null))", scripts[1]);
+ assertEquals(dry(createQueueInitString("theform:unsizedQueue",
"{'size':-1}", null)), scripts[1]);
- assertEquals(QUEUE_INIT_PROLOG_DRIED +
- "'theform:defaultSizeQueue',null,null))", scripts[2]);
+ assertEquals(dry(createQueueInitString("theform:defaultSizeQueue", null,
null)), scripts[2]);
}
public void testRenderRequestAttributes() throws Exception {
@@ -181,11 +203,14 @@
HtmlPage page = renderView();
String queueScript = dry(getQueueScript(page));
- String[] scripts = queueScript.split(";");
+ String[] scripts = splitScript(queueScript);
assertEquals(2, scripts.length);
- assertEquals(QUEUE_INIT_PROLOG_DRIED +
"'theform:queue1',null,{'timeout':50021,'queueonsubmit':function(request){submit_queue_handler()},'queueonerror':function(request,status,message){error_queue_handler()}}))",
scripts[0]);
- assertEquals(QUEUE_INIT_PROLOG_DRIED +
"'theform:queue2',null,{'ignoreDupResponses':true,'requestDelay':600,'queueonbeforedomupdate':function(request,event,data){beforedomupdate_handler()},'queueoncomplete':function(request,event,data){complete_handler()}}))",
scripts[1]);
+ assertEquals(dry(createQueueInitString("theform:queue1", null,
+ "{'timeout':50021,'queueonsubmit':function(request){submit_queue_handler()},'queueonerror':function(request,status,message){error_queue_handler()}}")),
scripts[0]);
+ assertEquals(dry(createQueueInitString("theform:queue2", null,
+ "{'ignoreDupResponses':true,'requestDelay':600,'queueonbeforedomupdate':function(request,event,data){beforedomupdate_handler()},'queueoncomplete':function(request,event,data){complete_handler()}}")),
+ scripts[1]);
}
public void testInvalidSizeExceededBehavior() throws Exception {
@@ -215,10 +240,10 @@
HtmlPage page = renderView();
String queueScript = dry(getQueueScript(page));
- String[] scripts = queueScript.split(";");
+ String[] scripts = splitScript(queueScript);
assertEquals(1, scripts.length);
- assertEquals(QUEUE_INIT_PROLOG_DRIED +
"'theform:testQueue',{'size':2},null))", scripts[0]);
+ assertEquals(dry(createQueueInitString("theform:testQueue",
"{'size':2}",null)), scripts[0]);
}
}