Author: nbelaevski
Date: 2010-05-24 15:33:42 -0400 (Mon, 24 May 2010)
New Revision: 17219
Removed:
root/core/trunk/impl/src/main/java/org/richfaces/context/RequestStateManager.java
root/core/trunk/impl/src/main/java/org/richfaces/context/RequestStateManagerPhaseCleaner.java
Modified:
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
root/core/trunk/impl/src/main/java/org/richfaces/context/SkinningResourcesPhaseListener.java
root/core/trunk/impl/src/main/resources/META-INF/faces-config.xml
root/ui/core/trunk/api/src/main/java/org/richfaces/component/QueuePreRenderViewListener.java
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/QueueResourceComponentRenderer.java
Log:
Support for "org.richfaces.queue.enabled" parameter redesigned
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-24
19:12:15 UTC (rev 17218)
+++
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2010-05-24
19:33:42 UTC (rev 17219)
@@ -32,18 +32,15 @@
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.faces.FacesException;
-import javax.faces.application.Application;
import javax.faces.application.ViewHandler;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.component.UIForm;
-import javax.faces.component.UIOutput;
import javax.faces.component.UIParameter;
import javax.faces.component.UIViewRoot;
import javax.faces.component.ValueHolder;
@@ -60,7 +57,6 @@
import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.util.HtmlDimensions;
import org.richfaces.context.ComponentIdResolver;
-import org.richfaces.context.RequestStateManager;
/**
* Util class for common render operations - render passthru html attributes,
@@ -1139,80 +1135,6 @@
}
}
- private UIComponent findInstalledResource(FacesContext context, String libraryName,
String resourceName,
- String target) {
-
- List<UIComponent> resourceComponents =
context.getViewRoot().getComponentResources(context, target);
- for (UIComponent component : resourceComponents) {
- Map<String, Object> attributes = component.getAttributes();
-
- if (resourceName.equals(attributes.get("name"))) {
- Object library = attributes.get("library");
-
- if ((libraryName == null && library == null) ||
libraryName.equals(library)) {
- return component;
- }
- }
- }
-
- return null;
- }
-
- public UIComponent findInstalledResource(FacesContext context, String libraryName,
String resourceName) {
- UIComponent component;
-
- component = findInstalledResource(context, libraryName, resourceName,
"head");
-
- if (component == null) {
- component = findInstalledResource(context, libraryName, resourceName,
"body");
- }
-
- if (component == null) {
- component = findInstalledResource(context, libraryName, resourceName,
"form");
- }
-
- return component;
- }
-
- public void addResource(FacesContext context, String libraryName, String
resourceName) {
- addResource(context, libraryName, resourceName, null);
- }
-
- public void addResource(FacesContext context, String libraryName, String
resourceName, String targetParam) {
- String resourceKey;
-
- if (libraryName != null && libraryName.length() != 0) {
- resourceKey = libraryName + '/' + resourceName;
- } else {
- resourceKey = resourceName;
- }
-
- Set<String> processedResources =
RequestStateManager.getProcessedResources(context);
- if (processedResources.contains(resourceKey)) {
- return ;
- }
-
- UIComponent resourceComponent = findInstalledResource(context, libraryName,
resourceName);
- if (resourceComponent == null) {
- Application application = context.getApplication();
- resourceComponent = application.createComponent(UIOutput.COMPONENT_TYPE);
-
- String rendererType =
application.getResourceHandler().getRendererTypeForResourceName(resourceName);
- resourceComponent.setRendererType(rendererType);
-
- if (libraryName != null && libraryName.length() != 0) {
- resourceComponent.getAttributes().put("library", libraryName);
- }
-
- resourceComponent.getAttributes().put("name", resourceName);
-
- String target = (targetParam != null ? targetParam : "head");
- context.getViewRoot().addComponentResource(context, resourceComponent,
target);
- }
-
- processedResources.add(resourceKey);
- }
-
/**
* Common HTML elements and attributes names.
*
Deleted:
root/core/trunk/impl/src/main/java/org/richfaces/context/RequestStateManager.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/context/RequestStateManager.java 2010-05-24
19:12:15 UTC (rev 17218)
+++
root/core/trunk/impl/src/main/java/org/richfaces/context/RequestStateManager.java 2010-05-24
19:33:42 UTC (rev 17219)
@@ -1,78 +0,0 @@
-/*
- * 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.context;
-
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import javax.faces.context.FacesContext;
-import javax.faces.event.PhaseId;
-
-/**
- * @author Nick Belaevski
- *
- */
-public final class RequestStateManager {
-
- private static final String ATTRIBUTE_NAME_PREFIX =
RequestStateManager.class.getName() + ":";
-
- private enum Sets {
- PROCESSED_RESOURCES("processedResources");
-
- private final String attributeName;
-
- private Sets(String propertyName) {
- this.attributeName = ATTRIBUTE_NAME_PREFIX + propertyName;
- }
-
- void clear(FacesContext context) {
- context.getAttributes().remove(attributeName);
- }
-
- public Set<String> getValue(FacesContext context) {
- Map<Object, Object> attributes = context.getAttributes();
-
- Set<String> set = (Set<String>) attributes.get(attributeName);
- if (set == null) {
- set = new HashSet<String>();
- attributes.put(attributeName, set);
- }
-
- return set;
- }
- };
-
- private RequestStateManager() {
- //only factory methods are allowed to be used
- }
-
- static void clear(FacesContext context) {
- if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
- RequestStateManager.Sets.PROCESSED_RESOURCES.clear(context);
- }
- }
-
- public static Set<String> getProcessedResources(FacesContext context) {
- return Sets.PROCESSED_RESOURCES.getValue(context);
- }
-}
Deleted:
root/core/trunk/impl/src/main/java/org/richfaces/context/RequestStateManagerPhaseCleaner.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/context/RequestStateManagerPhaseCleaner.java 2010-05-24
19:12:15 UTC (rev 17218)
+++
root/core/trunk/impl/src/main/java/org/richfaces/context/RequestStateManagerPhaseCleaner.java 2010-05-24
19:33:42 UTC (rev 17219)
@@ -1,49 +0,0 @@
-/*
- * 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.context;
-
-import javax.faces.event.PhaseEvent;
-import javax.faces.event.PhaseId;
-import javax.faces.event.PhaseListener;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class RequestStateManagerPhaseCleaner implements PhaseListener {
-
- /**
- *
- */
- private static final long serialVersionUID = -7736491845168435241L;
-
- public void afterPhase(PhaseEvent event) {
- }
-
- public void beforePhase(PhaseEvent event) {
- RequestStateManager.clear(event.getFacesContext());
- }
-
- public PhaseId getPhaseId() {
- return PhaseId.ANY_PHASE;
- }
-}
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/context/SkinningResourcesPhaseListener.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/context/SkinningResourcesPhaseListener.java 2010-05-24
19:12:15 UTC (rev 17218)
+++
root/core/trunk/impl/src/main/java/org/richfaces/context/SkinningResourcesPhaseListener.java 2010-05-24
19:33:42 UTC (rev 17219)
@@ -115,9 +115,9 @@
private UIComponent createComponentResource(FacesContext context) {
Application application = context.getApplication();
- UIComponent resourceComponent =
application.createComponent(UIOutput.COMPONENT_TYPE);
- resourceComponent.setRendererType(
-
application.getResourceHandler().getRendererTypeForResourceName(BOTH_SKINNING));
+ String rendererType =
application.getResourceHandler().getRendererTypeForResourceName(BOTH_SKINNING);
+ UIComponent resourceComponent = application.createComponent(context,
UIOutput.COMPONENT_TYPE, rendererType);
+
return resourceComponent;
}
Modified: root/core/trunk/impl/src/main/resources/META-INF/faces-config.xml
===================================================================
--- root/core/trunk/impl/src/main/resources/META-INF/faces-config.xml 2010-05-24 19:12:15
UTC (rev 17218)
+++ root/core/trunk/impl/src/main/resources/META-INF/faces-config.xml 2010-05-24 19:33:42
UTC (rev 17219)
@@ -80,8 +80,4 @@
-->
<!-- /render-kit -->
- <lifecycle>
-
<phase-listener>org.richfaces.context.RequestStateManagerPhaseCleaner</phase-listener>
- </lifecycle>
-
</faces-config>
Modified:
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 2010-05-24
19:12:15 UTC (rev 17218)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/component/QueuePreRenderViewListener.java 2010-05-24
19:33:42 UTC (rev 17219)
@@ -23,6 +23,7 @@
import java.util.List;
+import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.component.UIOutput;
import javax.faces.component.UIViewRoot;
@@ -31,6 +32,8 @@
import javax.faces.event.SystemEvent;
import javax.faces.event.SystemEventListener;
+import org.ajax4jsf.context.ContextInitParameters;
+
/**
* @author Nick Belaevski
*
@@ -50,19 +53,26 @@
UIViewRoot viewRoot = context.getViewRoot();
List<UIComponent> resources = viewRoot.getComponentResources(context,
HEAD);
+ boolean queueEnabled = ContextInitParameters.isQueueEnabled(context);
+
boolean resourceExists = false;
for (UIComponent resourceComponent : resources) {
if
(QUEUE_RESOURCE_COMPONENT_RENDERER_TYPE.equals(resourceComponent.getRendererType())
&&
UIOutput.COMPONENT_FAMILY.equals(resourceComponent.getFamily())) {
+ if (!queueEnabled) {
+ viewRoot.removeComponentResource(context, resourceComponent);
+ }
+
resourceExists = true;
break;
}
}
- if (!resourceExists) {
- UIComponent queueResourceComponent =
context.getApplication().createComponent(UIOutput.COMPONENT_TYPE);
-
queueResourceComponent.setRendererType(QUEUE_RESOURCE_COMPONENT_RENDERER_TYPE);
+ if (!resourceExists && queueEnabled) {
+ Application application = context.getApplication();
+ UIComponent queueResourceComponent = application.createComponent(context,
+ UIOutput.COMPONENT_TYPE, QUEUE_RESOURCE_COMPONENT_RENDERER_TYPE);
viewRoot.addComponentResource(context, queueResourceComponent);
}
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-24
19:12:15 UTC (rev 17218)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/QueueRendererBase.java 2010-05-24
19:33:42 UTC (rev 17219)
@@ -21,6 +21,8 @@
*/
package org.richfaces.renderkit.html;
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
@@ -33,7 +35,6 @@
import javax.faces.render.Renderer;
import org.ajax4jsf.context.ContextInitParameters;
-import org.ajax4jsf.renderkit.RendererUtils;
import org.richfaces.component.QueueRegistry;
import org.richfaces.log.RichfacesLogger;
import org.slf4j.Logger;
@@ -41,42 +42,34 @@
/**
* @author Nick Belaevski Base class for rendering Queue
*/
+@ResourceDependencies(value = {
+ @ResourceDependency(library = "javax.faces", name =
"jsf.js"),
+ @ResourceDependency(name = "jquery.js"),
+ @ResourceDependency(name = "richfaces.js")})
@ListenersFor({
@ListenerFor(systemEventClass = PostAddToViewEvent.class),
@ListenerFor(systemEventClass = PreRemoveFromViewEvent.class)
})
public abstract class QueueRendererBase extends Renderer implements
ComponentSystemEventListener {
- //TODO nick - handle ContextInitParameters.isGlobalQueueEnabled(FacesContext)
-
protected static final String QUEUE_ID_ATTRIBBUTE = "queueId";
protected static final String NAME_ATTRIBBUTE = "name";
protected static final Logger LOGGER = RichfacesLogger.COMPONENTS.getLogger();
- private final RendererUtils utils = RendererUtils.getInstance();
-
public void processEvent(ComponentSystemEvent event) throws AbortProcessingException
{
- UIComponent comp = event.getComponent();
FacesContext context = FacesContext.getCurrentInstance();
+
+ if (!ContextInitParameters.isQueueEnabled(context)) {
+ return;
+ }
+
+ UIComponent comp = event.getComponent();
String queueName = getQueueName(context, comp);
QueueRegistry queueRegistry = QueueRegistry.getInstance(context);
if (event instanceof PostAddToViewEvent) {
queueRegistry.addQueue(queueName, comp);
-
- //@ResourceDependency(library = "javax.faces", name =
"jsf.js"),
- //@ResourceDependency(name = "jquery.js"),
- //@ResourceDependency(name = "richfaces.js"),
- //@ResourceDependency(name = "richfaces-queue.js")
- utils.addResource(context, "javax.faces", "jsf.js");
- utils.addResource(context, null, "jquery.js");
- utils.addResource(context, null, "richfaces.js");
-
- if (ContextInitParameters.isQueueEnabled(context)) {
- utils.addResource(context, null, "richfaces-queue.js");
- //TODO nick - make queue resource transient?
- }
} else if (event instanceof PreRemoveFromViewEvent) {
queueRegistry.removeQueue(queueName);
}
Modified:
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 2010-05-24
19:12:15 UTC (rev 17218)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/QueueResourceComponentRenderer.java 2010-05-24
19:33:42 UTC (rev 17219)
@@ -26,13 +26,14 @@
import java.util.Map;
import java.util.Map.Entry;
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
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.context.ContextInitParameters;
import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.RendererUtils;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
@@ -44,6 +45,11 @@
*
*/
@JsfRenderer(type = "org.richfaces.QueueResourceComponentRenderer", family =
UIOutput.COMPONENT_FAMILY)
+@ResourceDependencies(value = {
+ @ResourceDependency(library = "javax.faces", name =
"jsf.js"),
+ @ResourceDependency(name = "jquery.js"),
+ @ResourceDependency(name = "richfaces.js"),
+ @ResourceDependency(name = "richfaces-queue.js")})
public class QueueResourceComponentRenderer extends Renderer {
private static final String FUNCTION_NAME =
"RichFaces.queue.setQueueOptions";
@@ -70,7 +76,7 @@
super.encodeEnd(context, component);
QueueRegistry registry = QueueRegistry.getInstance(context);
- if (ContextInitParameters.isQueueEnabled(context) && registry != null
&& registry.hasQueuesToEncode()) {
+ if (registry != null && registry.hasQueuesToEncode()) {
ResponseWriter writer = context.getResponseWriter();
writer.startElement(HTML.SCRIPT_ELEM, component);