Author: nbelaevski
Date: 2010-05-23 13:53:50 -0400 (Sun, 23 May 2010)
New Revision: 17192
Added:
root/ui/core/trunk/api/src/main/java/org/richfaces/component/QueuePreRenderViewListener.java
root/ui/core/trunk/api/src/main/java/org/richfaces/component/QueueRegistry.java
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/QueueResourceComponentRenderer.java
root/ui/core/trunk/api/src/main/resources/META-INF/queue-prender-listener.faces-config.xml
root/ui/core/trunk/api/src/test/resources/org/richfaces/component/nonQueue.xhtml
root/ui/core/trunk/api/src/test/resources/org/richfaces/component/queue.xhtml
Removed:
root/core/trunk/impl/src/main/java/org/ajax4jsf/component/QueueRegistry.java
root/core/trunk/impl/src/main/java/org/richfaces/context/PreRenderViewListener.java
root/core/trunk/impl/src/main/resources/META-INF/prerenderview-listener.faces-config.xml
root/ui/core/trunk/api/src/test/resources/org/ajax4jsf/component/nonQueue.xhtml
root/ui/core/trunk/api/src/test/resources/org/ajax4jsf/component/queue.xhtml
Modified:
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/QueueRendererBase.java
root/ui/core/trunk/api/src/test/java/org/richfaces/component/QueueRendererTest.java
Log:
Queue redesign & fixes
Deleted: root/core/trunk/impl/src/main/java/org/ajax4jsf/component/QueueRegistry.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/ajax4jsf/component/QueueRegistry.java 2010-05-22
00:13:51 UTC (rev 17191)
+++
root/core/trunk/impl/src/main/java/org/ajax4jsf/component/QueueRegistry.java 2010-05-23
17:53:50 UTC (rev 17192)
@@ -1,78 +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.component;
-
-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 final class QueueRegistry {
- private static final String REGISTRY_ATTRIBUTE_NAME = QueueRegistry.class.getName();
- private Map<String, Object> queuesData = new LinkedHashMap<String,
Object>();
- private QueueRegistry() {
- }
-
- public static QueueRegistry getInstance(FacesContext context) {
- ExternalContext externalContext = context.getExternalContext();
- Map<String, Object> requestMap = externalContext.getRequestMap();
- QueueRegistry registry = (QueueRegistry)
requestMap.get(REGISTRY_ATTRIBUTE_NAME);
-
- if (registry == null) {
- registry = new QueueRegistry();
- requestMap.put(REGISTRY_ATTRIBUTE_NAME, registry);
- }
-
- return registry;
- }
-
- public void registerQueue(FacesContext context, String clientName, Object data) {
- if (!containsQueue(clientName)) {
- queuesData.put(clientName, data);
- }else{
- context.getExternalContext().log("Queue with name '" +
clientName + "' has already been registered");
- }
- }
-
- public void removeQueue(FacesContext context, String clientName) {
- if (!containsQueue(clientName)) {
- queuesData.remove(clientName);
- }
- }
-
- public boolean containsQueue(String name) {
- return queuesData.containsKey(name);
- }
-
- public Map<String, Object> getRegisteredQueues(FacesContext context) {
- return queuesData;
- }
-
- public boolean hasQueuesToEncode() {
- return !queuesData.isEmpty();
- }
-}
\ No newline at end of file
Modified: root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2010-05-22
00:13:51 UTC (rev 17191)
+++
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2010-05-23
17:53:50 UTC (rev 17192)
@@ -1274,5 +1274,9 @@
public static final String VALIGN_ATTRIBUTE = "valign";
public static final String VALUE_ATTRIBUTE = "value";
public static final String WIDTH_ATTRIBUTE = "width";
+
+ public static final String REL_STYLESHEET = "stylesheet";
+ public static final String CSS_TYPE = "text/css";
+ public static final String JAVASCRIPT_TYPE = "text/javascript";
}
}
Deleted:
root/core/trunk/impl/src/main/java/org/richfaces/context/PreRenderViewListener.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/context/PreRenderViewListener.java 2010-05-22
00:13:51 UTC (rev 17191)
+++
root/core/trunk/impl/src/main/java/org/richfaces/context/PreRenderViewListener.java 2010-05-23
17:53:50 UTC (rev 17192)
@@ -1,190 +0,0 @@
-package org.richfaces.context;
-
-/**
- * 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
- */
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIOutput;
-import javax.faces.context.FacesContext;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.PreRenderViewEvent;
-import javax.faces.event.SystemEvent;
-import javax.faces.event.SystemEventListener;
-
-import org.ajax4jsf.component.QueueRegistry;
-import org.ajax4jsf.javascript.ScriptUtils;
-
-/**
- * This class used for determining what standard resources should be encoded(queue,
skinning etc.). Implements SystemEventListener
- * and reacts on PreRenderViewEvent
- *
- * @author amarkhel
- * @since 4.0
- */
-public class PreRenderViewListener implements SystemEventListener {
-
- private static final String MARKER_ATTRIBBUTE = "marker";
-
- private static final String FUNCTION_END = ");";
-
- private static final String FUNCTION_NAME =
"RichFaces.queue.setQueueOptions(";
-
- private static final String SCRIPT_END = "</script>";
-
- private static final String SCRIPT_START = "<script
type=\"text/javascript\">";
-
- private static final String QUEUE_RESOURCE = "richFacesQueueResource";
-
- private static final String VALUE_ATTRIBBUTE = "value";
-
- private static final String HEAD = "head";
-
- private static final String NAME_ATTRIBBUTE = "name";
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.event.SystemEventListener#isListenerForSource(java.lang.Object)
- */
- public boolean isListenerForSource(Object source) {
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
javax.faces.event.SystemEventListener#processEvent(javax.faces.event.SystemEvent)
- */
- public void processEvent(SystemEvent event) throws AbortProcessingException {
-
- if (event instanceof PreRenderViewEvent) {
- encodeQueueResource();
- }
- }
-
- private void encodeQueueResource() {
- FacesContext context = FacesContext.getCurrentInstance();
- if (QueueRegistry.getInstance(context).hasQueuesToEncode()) {
- StringBuilder sb = constructQueueScript(context);
- addQueueResourceToView(context, sb);
- }
- }
-
- private void addQueueResourceToView(FacesContext context, StringBuilder sb) {
- removeComponentResource(context, QUEUE_RESOURCE);
- HashMap<String, Object> hashMap = new HashMap<String, Object>();
- hashMap.put(MARKER_ATTRIBBUTE, QUEUE_RESOURCE);
- hashMap.put(VALUE_ATTRIBBUTE, sb.toString());
- addComponentResource(context, hashMap, null);
- }
-
- private StringBuilder constructQueueScript(FacesContext context) {
- StringBuilder sb = new StringBuilder(1024);
- sb.append(SCRIPT_START);
- sb.append(FUNCTION_NAME);
- sb.append("{");
- addParameter(context, sb);
- sb.append("}");
- sb.append(FUNCTION_END);
- sb.append(SCRIPT_END);
- return sb;
- }
-
- private void addParameter(FacesContext context, StringBuilder sb) {
- Map<String, Object> registeredQueues =
QueueRegistry.getInstance(context).getRegisteredQueues(context);
- boolean firstElementAdded = false;
- for (Map.Entry<String, Object> queue : registeredQueues.entrySet()) {
- UIComponent queueComp = (UIComponent) queue.getValue();
- firstElementAdded = appendQueueName(sb, firstElementAdded, queue);
- appendQueueOptions(sb, queueComp);
- }
- }
-
- private void appendQueueOptions(StringBuilder sb, UIComponent queueComp) {
- boolean firstAttribbuteAdded = false;
- for (QueueOptions queueOption : QueueOptions.values()) {
- String attribbute = queueOption.name();
- if (shouldRenderOption(queueComp, attribbute)) {
- if (firstAttribbuteAdded) {
- sb.append(",");
- } else {
- firstAttribbuteAdded = true;
- }
- sb.append(attribbute);
- sb.append(":'");
- sb.append(queueComp.getAttributes().get(attribbute));
- sb.append("'");
- }
- }
- sb.append("}");
- }
-
- private boolean shouldRenderOption(UIComponent queueComp, String attribbute) {
- return queueComp.getAttributes().get(attribbute) != null
- && ScriptUtils.shouldRenderAttribute(attribbute,
queueComp.getAttributes().get(attribbute));
- }
-
- private boolean appendQueueName(StringBuilder sb, boolean firstElementAdded,
Map.Entry<String, Object> queue) {
- if (firstElementAdded) {
- sb.append(",");
- } else {
- firstElementAdded = true;
- }
- sb.append("'");
- sb.append(queue.getKey());
- sb.append("'");
- sb.append(":{");
- return firstElementAdded;
- }
-
- private void addComponentResource(FacesContext context, Map<String, Object>
params, String rendererType){
- UIOutput output = new UIOutput();
- if(rendererType != null){
- output.setRendererType(rendererType);
- }
- for(Map.Entry<String, Object> parameter : params.entrySet()){
- output.getAttributes().put(parameter.getKey(), parameter.getValue());
- }
- context.getViewRoot().addComponentResource(context, output, HEAD);
- }
-
- private void removeComponentResource(FacesContext context, String resourceId){
- List<UIComponent> result =
context.getViewRoot().getComponentResources(context, HEAD);
- for (UIComponent resource : result) {
- if(resource.getAttributes().get(MARKER_ATTRIBBUTE) != null){
- String resourceName =
resource.getAttributes().get(MARKER_ATTRIBBUTE).toString();
- if (resourceName.equals(resourceId)) {
- context.getViewRoot().removeComponentResource(context, resource,
HEAD);
- break;
- }
- }
- }
- }
- protected static enum QueueOptions {
- onbeforedomupdate, oncomplete, onerror, onevent, onrequestdequeue,
onrequestqueue, onsubmit, requestDelay, timeout, status, queueId, ignoreDupResponses,
requestGroupingId
-
- }
-
-}
\ No newline at end of file
Deleted:
root/core/trunk/impl/src/main/resources/META-INF/prerenderview-listener.faces-config.xml
===================================================================
---
root/core/trunk/impl/src/main/resources/META-INF/prerenderview-listener.faces-config.xml 2010-05-22
00:13:51 UTC (rev 17191)
+++
root/core/trunk/impl/src/main/resources/META-INF/prerenderview-listener.faces-config.xml 2010-05-23
17:53:50 UTC (rev 17192)
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
version="2.0">
- <name>richfaces</name>
- <application>
- <system-event-listener>
- <system-event-listener-class>org.richfaces.context.PreRenderViewListener</system-event-listener-class>
- <system-event-class>javax.faces.event.PreRenderViewEvent</system-event-class>
- </system-event-listener>
- </application>
-
-</faces-config>
\ No newline at end of file
Added:
root/ui/core/trunk/api/src/main/java/org/richfaces/component/QueuePreRenderViewListener.java
===================================================================
---
root/ui/core/trunk/api/src/main/java/org/richfaces/component/QueuePreRenderViewListener.java
(rev 0)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/component/QueuePreRenderViewListener.java 2010-05-23
17:53:50 UTC (rev 17192)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.component;
+
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIOutput;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class QueuePreRenderViewListener implements SystemEventListener {
+
+ private static final String HEAD = "head";
+
+ private static final String QUEUE_RESOURCE_COMPONENT_RENDERER_TYPE =
"org.richfaces.QueueResourceComponentRenderer";
+
+ public boolean isListenerForSource(Object source) {
+ return true;
+ }
+
+ public void processEvent(SystemEvent event) throws AbortProcessingException {
+ FacesContext context = FacesContext.getCurrentInstance();
+ UIViewRoot viewRoot = context.getViewRoot();
+ List<UIComponent> resources = viewRoot.getComponentResources(context,
HEAD);
+
+ boolean resourceExists = false;
+ for (UIComponent resourceComponent : resources) {
+ if
(QUEUE_RESOURCE_COMPONENT_RENDERER_TYPE.equals(resourceComponent.getRendererType())
&&
+ UIOutput.COMPONENT_FAMILY.equals(resourceComponent.getFamily())) {
+
+ resourceExists = true;
+ break;
+ }
+ }
+
+ if (!resourceExists) {
+ UIComponent queueResourceComponent =
context.getApplication().createComponent(UIOutput.COMPONENT_TYPE);
+
queueResourceComponent.setRendererType(QUEUE_RESOURCE_COMPONENT_RENDERER_TYPE);
+
+ viewRoot.addComponentResource(context, queueResourceComponent);
+ }
+ }
+
+}
Copied: root/ui/core/trunk/api/src/main/java/org/richfaces/component/QueueRegistry.java
(from rev 17186,
root/core/trunk/impl/src/main/java/org/ajax4jsf/component/QueueRegistry.java)
===================================================================
--- root/ui/core/trunk/api/src/main/java/org/richfaces/component/QueueRegistry.java
(rev 0)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/component/QueueRegistry.java 2010-05-23
17:53:50 UTC (rev 17192)
@@ -0,0 +1,88 @@
+/**
+ * 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 java.util.LinkedHashMap;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.log.RichfacesLogger;
+import org.slf4j.Logger;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.0
+ */
+public final class QueueRegistry {
+
+ public static final String QUEUE_SCRIPT_CLIENT_ID = "org.richfaces.queue";
+
+ private static final Logger LOGGER = RichfacesLogger.COMPONENTS.getLogger();
+
+ private static final String REGISTRY_ATTRIBUTE_NAME = QueueRegistry.class.getName();
+ private Map<String, UIComponent> queuesData = new LinkedHashMap<String,
UIComponent>();
+
+ private QueueRegistry() {
+ }
+
+ public static QueueRegistry getInstance(FacesContext context) {
+ ExternalContext externalContext = context.getExternalContext();
+ Map<String, Object> requestMap = externalContext.getRequestMap();
+ QueueRegistry registry = (QueueRegistry)
requestMap.get(REGISTRY_ATTRIBUTE_NAME);
+
+ if (registry == null) {
+ registry = new QueueRegistry();
+ requestMap.put(REGISTRY_ATTRIBUTE_NAME, registry);
+ }
+
+ return registry;
+ }
+
+ public void registerQueue(String clientName, UIComponent component) {
+ if (!containsQueue(clientName)) {
+ queuesData.put(clientName, component);
+ } else {
+ LOGGER.warn("Queue with name '" + clientName + "' has
already been registered");
+ }
+ }
+
+ public void removeQueue(String clientName) {
+ if (!containsQueue(clientName)) {
+ queuesData.remove(clientName);
+ }
+ }
+
+ public boolean containsQueue(String name) {
+ return queuesData.containsKey(name);
+ }
+
+ public Map<String, UIComponent> getRegisteredQueues() {
+ return queuesData;
+ }
+
+ public boolean hasQueuesToEncode() {
+ return !queuesData.isEmpty();
+ }
+}
\ No newline at end of file
Modified:
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/QueueRendererBase.java
===================================================================
---
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/QueueRendererBase.java 2010-05-22
00:13:51 UTC (rev 17191)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/QueueRendererBase.java 2010-05-23
17:53:50 UTC (rev 17192)
@@ -35,9 +35,9 @@
import javax.faces.event.PreRemoveFromViewEvent;
import javax.faces.render.Renderer;
-import org.ajax4jsf.component.QueueRegistry;
import org.ajax4jsf.context.ContextInitParameters;
import org.richfaces.component.AbstractQueue;
+import org.richfaces.component.QueueRegistry;
import org.richfaces.log.RichfacesLogger;
import org.slf4j.Logger;
@@ -63,10 +63,10 @@
if (event instanceof PostAddToViewEvent) {
String name = findAndSetQueueName(comp);
if (name != null) {
- QueueRegistry.getInstance(context).registerQueue(context, name, comp);
+ QueueRegistry.getInstance(context).registerQueue(name, comp);
}
} else if (event instanceof PreRemoveFromViewEvent) {
- QueueRegistry.getInstance(context).removeQueue(context, getQueueName(comp));
+ QueueRegistry.getInstance(context).removeQueue(getQueueName(comp));
}
}
Added:
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/QueueResourceComponentRenderer.java
===================================================================
---
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/QueueResourceComponentRenderer.java
(rev 0)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/QueueResourceComponentRenderer.java 2010-05-23
17:53:50 UTC (rev 17192)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.renderkit.html;
+
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIOutput;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.Renderer;
+
+import org.ajax4jsf.javascript.ScriptUtils;
+import org.ajax4jsf.renderkit.RendererUtils;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.component.QueueRegistry;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@JsfRenderer(type = "org.richfaces.QueueResourceComponentRenderer", family =
UIOutput.COMPONENT_FAMILY)
+public class QueueResourceComponentRenderer extends Renderer {
+
+ private static final String FUNCTION_NAME =
"RichFaces.queue.setQueueOptions";
+
+ private final RendererUtils utils = RendererUtils.getInstance();
+
+ private enum QueueOptions {
+ onbeforedomupdate, oncomplete, onerror, onevent, onrequestdequeue,
onrequestqueue, onsubmit,
+ requestDelay, timeout, status, queueId, ignoreDupResponses, requestGroupingId
+ }
+
+ private void appendOptions(UIComponent queue, Map<String, Object> optionsHash)
{
+ Map<String, Object> attributes = queue.getAttributes();
+
+ for (QueueOptions option : QueueOptions.values()) {
+ String optionName = option.name();
+ Object value = attributes.get(optionName);
+ utils.addToScriptHash(optionsHash, optionName, value);
+ }
+ }
+
+ @Override
+ public void encodeEnd(FacesContext context, UIComponent component) throws IOException
{
+ super.encodeEnd(context, component);
+
+ QueueRegistry registry = QueueRegistry.getInstance(context);
+ if (registry != null && registry.hasQueuesToEncode()) {
+ ResponseWriter writer = context.getResponseWriter();
+
+ writer.startElement(HTML.SCRIPT_ELEM, component);
+ writer.writeAttribute(HTML.ID_ATTRIBUTE,
+
context.getExternalContext().encodeNamespace(QueueRegistry.QUEUE_SCRIPT_CLIENT_ID),
null);
+ writer.writeAttribute(HTML.TYPE_ATTR, HTML.JAVASCRIPT_TYPE, null);
+
+ writer.writeText(FUNCTION_NAME, null);
+ writer.writeText("({", null);
+
+ Map<String,Object> queueOptionsMap = new LinkedHashMap<String,
Object>();
+
+ boolean isFirst = true;
+ Map<String, UIComponent> registeredQueues =
registry.getRegisteredQueues();
+ for (Entry<String, UIComponent> queueEntry :
registeredQueues.entrySet()) {
+ if (isFirst) {
+ isFirst = false;
+ } else {
+ writer.writeText(",", null);
+ }
+
+ queueOptionsMap.clear();
+
+ String queueName = queueEntry.getKey();
+ UIComponent queue = queueEntry.getValue();
+
+ appendOptions(queue, queueOptionsMap);
+
+ ScriptUtils.writeToStream(writer, queueName);
+ writer.writeText(":", null);
+ ScriptUtils.writeToStream(writer, queueOptionsMap);
+ }
+
+ writer.writeText("});", null);
+
+ writer.endElement(HTML.SCRIPT_ELEM);
+ }
+ }
+}
Added:
root/ui/core/trunk/api/src/main/resources/META-INF/queue-prender-listener.faces-config.xml
===================================================================
---
root/ui/core/trunk/api/src/main/resources/META-INF/queue-prender-listener.faces-config.xml
(rev 0)
+++
root/ui/core/trunk/api/src/main/resources/META-INF/queue-prender-listener.faces-config.xml 2010-05-23
17:53:50 UTC (rev 17192)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
+ version="2.0">
+
+ <application>
+ <system-event-listener>
+ <system-event-listener-class>org.richfaces.component.QueuePreRenderViewListener</system-event-listener-class>
+ <system-event-class>javax.faces.event.PreRenderViewEvent</system-event-class>
+ </system-event-listener>
+ </application>
+</faces-config>
\ No newline at end of file
Modified:
root/ui/core/trunk/api/src/test/java/org/richfaces/component/QueueRendererTest.java
===================================================================
---
root/ui/core/trunk/api/src/test/java/org/richfaces/component/QueueRendererTest.java 2010-05-22
00:13:51 UTC (rev 17191)
+++
root/ui/core/trunk/api/src/test/java/org/richfaces/component/QueueRendererTest.java 2010-05-23
17:53:50 UTC (rev 17192)
@@ -23,14 +23,18 @@
package org.richfaces.component;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
import org.jboss.test.faces.ApplicationServer;
import org.jboss.test.faces.htmlunit.HtmlUnitEnvironment;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+
+import com.gargoylesoftware.htmlunit.html.DomNode;
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
/**
@@ -39,16 +43,15 @@
*/
public class QueueRendererTest{
- private static final String EXPECTED_QUEUE_SCRIPT =
"'first':{requestDelay:'400',timeout:'100',ignoreDupResponses:'true'},'form':{requestDelay:'400'},'form:firstAttach':{timeout:'300',queueId:'form',requestGroupingId:'request'},'second':{requestDelay:'400',timeout:'100',ignoreDupResponses:'true'},'form:linkAttach':{timeout:'500',queueId:'second'},'form:secondAttach':{queueId:'form'}";
+ private static final String EXPECTED_QUEUE_SCRIPT =
"RichFaces.queue.setQueueOptions({" +
+ "'first': {'requestDelay': 400, 'timeout': 100,
'ignoreDupResponses': true}," +
+ "'form': {'requestDelay': 400}," +
+ "'form:firstAttach': {'timeout': 300, 'queueId':
'form', 'requestGroupingId': 'request'}," +
+ "'second': {'requestDelay': 400, 'timeout': 100,
'ignoreDupResponses': true}," +
+ "'form:linkAttach': {'timeout': 500, 'queueId':
'second'}," +
+ "'form:secondAttach': {'queueId': 'form'}" +
+ "});";
- private static final String QUEUE_SCRIPT_MUST_BE_NOT_NULL = "Queue script must be
not null";
-
- private static final String QUEUE_SCRIPT_MUST_BE_NULL = "Queue script must be
null";
-
- private static final String SCRIPT = "</script>";
-
- private static final String RICH_FACES_QUEUE_SET_QUEUE_OPTIONS =
"RichFaces.queue.setQueueOptions(";
-
protected HtmlPage page;
protected HtmlUnitEnvironment facesEnvironment;
@@ -59,8 +62,8 @@
facesEnvironment = new HtmlUnitEnvironment();
ApplicationServer facesServer = facesEnvironment.getServer();
- facesServer.addResource("/queue.xhtml",
"org/ajax4jsf/component/queue.xhtml");
- facesServer.addResource("/nonQueue.xhtml",
"org/ajax4jsf/component/nonQueue.xhtml");
+ facesServer.addResource("/queue.xhtml",
"org/richfaces/component/queue.xhtml");
+ facesServer.addResource("/nonQueue.xhtml",
"org/richfaces/component/nonQueue.xhtml");
facesEnvironment.start();
}
@@ -68,18 +71,17 @@
@After
public void tearDown() throws Exception {
this.page = null;
+
this.facesEnvironment.release();
this.facesEnvironment = null;
}
-
@Test
public void testQueue() throws Exception {
- page = renderView("/queue.jsf");
- String responseString = page.getWebResponse().getContentAsString();
- String queueScript = extractQueueScript(responseString);
- assertNotNull(queueScript, QUEUE_SCRIPT_MUST_BE_NOT_NULL);
- assertEquals(queueScript, EXPECTED_QUEUE_SCRIPT);
+ page = facesEnvironment.getPage("/queue.jsf");
+ String queueScript = extractQueueScript(page);
+ assertNotNull(queueScript, "Queue script must be not null");
+ assertEquals(dehydrate(EXPECTED_QUEUE_SCRIPT), dehydrate(queueScript));
/*String[] queueArray = queueScript.split("},");
//String[] queueNames = new String[queueArray.length];
//String[] queueOptions = new String[queueArray.length];
@@ -97,28 +99,32 @@
@Test
public void testPageWithoutQueue() throws Exception {
- page = renderView("/nonQueue.jsf");
- String responseString = page.getWebResponse().getContentAsString();
- String queueScript = extractQueueScript(responseString);
- assertNull(QUEUE_SCRIPT_MUST_BE_NULL, queueScript);
+ page = facesEnvironment.getPage("/nonQueue.jsf");
+ String queueScript = extractQueueScript(page);
+ assertNull("Queue script must be null", queueScript);
}
- private String extractQueueScript(String responseString) {
- String queueScript = null;
- if(responseString.lastIndexOf(RICH_FACES_QUEUE_SET_QUEUE_OPTIONS) != -1){
- queueScript =
responseString.substring(responseString.lastIndexOf(RICH_FACES_QUEUE_SET_QUEUE_OPTIONS) +
RICH_FACES_QUEUE_SET_QUEUE_OPTIONS.length() +1);
- if(queueScript.indexOf(SCRIPT) != -1){
- queueScript = queueScript.substring(0, queueScript.indexOf(SCRIPT) -3);
- }else{
- return null;
- }
+ private String dehydrate(String s) {
+ return s.replaceAll("\\s+", "");
+ }
+
+ private String getTextContent(HtmlElement element) {
+ StringBuilder sb = new StringBuilder();
+
+ for (DomNode node = element.getFirstChild(); node != null; node =
node.getNextSibling()) {
+ sb.append(node.getNodeValue());
}
- return queueScript;
+
+ return sb.toString();
}
- protected HtmlPage renderView(String url) throws Exception {
- page = facesEnvironment.getPage(url);
- return page;
+ private String extractQueueScript(HtmlPage page) {
+ HtmlElement scriptElement =
page.getElementById(QueueRegistry.QUEUE_SCRIPT_CLIENT_ID);
+ if (scriptElement != null) {
+ return getTextContent(scriptElement);
+ }
+ return null;
}
+
}
\ No newline at end of file
Deleted: root/ui/core/trunk/api/src/test/resources/org/ajax4jsf/component/nonQueue.xhtml
===================================================================
---
root/ui/core/trunk/api/src/test/resources/org/ajax4jsf/component/nonQueue.xhtml 2010-05-22
00:13:51 UTC (rev 17191)
+++
root/ui/core/trunk/api/src/test/resources/org/ajax4jsf/component/nonQueue.xhtml 2010-05-23
17:53:50 UTC (rev 17192)
@@ -1,35 +0,0 @@
-<html
xmlns:h="http://java.sun.com/jsf/html"
-
xmlns:f="http://java.sun.com/jsf/core"
-
xmlns:a4j="http://richfaces.org/a4j"
-
xmlns:ui="http://java.sun.com/jsf/facelets">
-
- <h:head>
- <title>Test queue page</title>
-
- <h:outputScript name="jsf.js" library="javax.faces" />
- <h:outputScript name="jquery.js" />
- <h:outputScript name="richfaces.js" />
- <h:outputScript name="richfaces-queue.js" />
-
- </h:head>
- <h:body>
- <h:form id="form">
- <a4j:ajax>
- <h:inputText />
-
- </a4j:ajax>
- <a4j:ajax event="valueChange">
- <h:panelGroup>
- <a4j:ajax event="valueChange">
- <h:inputText />
-
- <a4j:commandLink value="Link"/>
-
- </a4j:ajax>
- </h:panelGroup>
- </a4j:ajax>
- <h:commandButton value="G"/>
- </h:form>
-
- </h:body>
-</html>
\ No newline at end of file
Deleted: root/ui/core/trunk/api/src/test/resources/org/ajax4jsf/component/queue.xhtml
===================================================================
---
root/ui/core/trunk/api/src/test/resources/org/ajax4jsf/component/queue.xhtml 2010-05-22
00:13:51 UTC (rev 17191)
+++
root/ui/core/trunk/api/src/test/resources/org/ajax4jsf/component/queue.xhtml 2010-05-23
17:53:50 UTC (rev 17192)
@@ -1,42 +0,0 @@
-<html
xmlns:h="http://java.sun.com/jsf/html"
-
xmlns:f="http://java.sun.com/jsf/core"
-
xmlns:a4j="http://richfaces.org/a4j"
-
xmlns:ui="http://java.sun.com/jsf/facelets">
-
- <h:head>
- <title>Test queue page</title>
-
- <h:outputScript name="jsf.js" library="javax.faces" />
- <h:outputScript name="jquery.js" />
- <h:outputScript name="richfaces.js" />
- <h:outputScript name="richfaces-queue.js" />
-
- </h:head>
- <h:body>
- <a4j:queue name="first" ignoreDupResponses="true"
timeout="100" requestDelay="400"/>
- <h:form id="form">
- <a4j:queue ignoreDupResponses="false" requestDelay="400"/>
- <a4j:ajax>
- <h:inputText />
-
- <a4j:attachQueue requestGroupingId="request" timeout="300"
id="firstAttach" />
- </a4j:ajax>
- <a4j:queue name="second" ignoreDupResponses="true"
timeout="100" requestDelay="400"/>
- <a4j:ajax event="valueChange">
- <h:panelGroup>
- <a4j:ajax event="valueChange">
- <h:inputText />
-
- <a4j:commandLink value="Link">
- <a4j:attachQueue name="second" timeout="500"
id="linkAttach" />
- </a4j:commandLink>
-
- <a4j:attachQueue id="secondAttach" />
- </a4j:ajax>
- </h:panelGroup>
- </a4j:ajax>
- <h:commandButton value="G"/>
- </h:form>
-
- </h:body>
-</html>
\ No newline at end of file
Copied: root/ui/core/trunk/api/src/test/resources/org/richfaces/component/nonQueue.xhtml
(from rev 17186,
root/ui/core/trunk/api/src/test/resources/org/ajax4jsf/component/nonQueue.xhtml)
===================================================================
--- root/ui/core/trunk/api/src/test/resources/org/richfaces/component/nonQueue.xhtml
(rev 0)
+++
root/ui/core/trunk/api/src/test/resources/org/richfaces/component/nonQueue.xhtml 2010-05-23
17:53:50 UTC (rev 17192)
@@ -0,0 +1,35 @@
+<html
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:ui="http://java.sun.com/jsf/facelets">
+
+ <h:head>
+ <title>Test queue page</title>
+
+ <h:outputScript name="jsf.js" library="javax.faces" />
+ <h:outputScript name="jquery.js" />
+ <h:outputScript name="richfaces.js" />
+ <h:outputScript name="richfaces-queue.js" />
+
+ </h:head>
+ <h:body>
+ <h:form id="form">
+ <a4j:ajax>
+ <h:inputText />
+
+ </a4j:ajax>
+ <a4j:ajax event="valueChange">
+ <h:panelGroup>
+ <a4j:ajax event="valueChange">
+ <h:inputText />
+
+ <a4j:commandLink value="Link"/>
+
+ </a4j:ajax>
+ </h:panelGroup>
+ </a4j:ajax>
+ <h:commandButton value="G"/>
+ </h:form>
+
+ </h:body>
+</html>
\ No newline at end of file
Copied: root/ui/core/trunk/api/src/test/resources/org/richfaces/component/queue.xhtml
(from rev 17186,
root/ui/core/trunk/api/src/test/resources/org/ajax4jsf/component/queue.xhtml)
===================================================================
--- root/ui/core/trunk/api/src/test/resources/org/richfaces/component/queue.xhtml
(rev 0)
+++
root/ui/core/trunk/api/src/test/resources/org/richfaces/component/queue.xhtml 2010-05-23
17:53:50 UTC (rev 17192)
@@ -0,0 +1,42 @@
+<html
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:ui="http://java.sun.com/jsf/facelets">
+
+ <h:head>
+ <title>Test queue page</title>
+
+ <h:outputScript name="jsf.js" library="javax.faces" />
+ <h:outputScript name="jquery.js" />
+ <h:outputScript name="richfaces.js" />
+ <h:outputScript name="richfaces-queue.js" />
+
+ </h:head>
+ <h:body>
+ <a4j:queue name="first" ignoreDupResponses="true"
timeout="100" requestDelay="400"/>
+ <h:form id="form">
+ <a4j:queue ignoreDupResponses="false" requestDelay="400"/>
+ <a4j:ajax>
+ <h:inputText />
+
+ <a4j:attachQueue requestGroupingId="request" timeout="300"
id="firstAttach" />
+ </a4j:ajax>
+ <a4j:queue name="second" ignoreDupResponses="true"
timeout="100" requestDelay="400"/>
+ <a4j:ajax event="valueChange">
+ <h:panelGroup>
+ <a4j:ajax event="valueChange">
+ <h:inputText />
+
+ <a4j:commandLink value="Link">
+ <a4j:attachQueue name="second" timeout="500"
id="linkAttach" />
+ </a4j:commandLink>
+
+ <a4j:attachQueue id="secondAttach" />
+ </a4j:ajax>
+ </h:panelGroup>
+ </a4j:ajax>
+ <h:commandButton value="G"/>
+ </h:form>
+
+ </h:body>
+</html>
\ No newline at end of file