Author: nbelaevski
Date: 2010-07-13 14:37:09 -0400 (Tue, 13 Jul 2010)
New Revision: 18012
Modified:
root/ui/core/trunk/ui/src/main/java/org/richfaces/component/QueuePreRenderViewListener.java
root/ui/core/trunk/ui/src/main/java/org/richfaces/component/QueueRegistry.java
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/QueueResourceComponentRenderer.java
root/ui/core/trunk/ui/src/test/java/org/richfaces/component/QueueRendererTest.java
Log:
Fixed duplicate ID exception caused by queuing feature
Modified:
root/ui/core/trunk/ui/src/main/java/org/richfaces/component/QueuePreRenderViewListener.java
===================================================================
---
root/ui/core/trunk/ui/src/main/java/org/richfaces/component/QueuePreRenderViewListener.java 2010-07-13
18:31:23 UTC (rev 18011)
+++
root/ui/core/trunk/ui/src/main/java/org/richfaces/component/QueuePreRenderViewListener.java 2010-07-13
18:37:09 UTC (rev 18012)
@@ -21,8 +21,6 @@
*/
package org.richfaces.component;
-import java.util.List;
-
import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.component.UIOutput;
@@ -40,8 +38,6 @@
*/
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) {
@@ -51,30 +47,19 @@
public void processEvent(SystemEvent event) throws AbortProcessingException {
FacesContext context = FacesContext.getCurrentInstance();
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 && queueEnabled) {
+ if (queueEnabled) {
Application application = context.getApplication();
UIComponent queueResourceComponent = application.createComponent(context,
UIOutput.COMPONENT_TYPE, QUEUE_RESOURCE_COMPONENT_RENDERER_TYPE);
+ //fix for JSF duplicate ID exception
+ queueResourceComponent.setId(QueueRegistry.QUEUE_SCRIPT_ID);
+
viewRoot.addComponentResource(context, queueResourceComponent);
+ } else {
+ //queue can be switched off at application level, not a page level, so no
need to remove it if it is switched off
}
}
Modified: root/ui/core/trunk/ui/src/main/java/org/richfaces/component/QueueRegistry.java
===================================================================
---
root/ui/core/trunk/ui/src/main/java/org/richfaces/component/QueueRegistry.java 2010-07-13
18:31:23 UTC (rev 18011)
+++
root/ui/core/trunk/ui/src/main/java/org/richfaces/component/QueueRegistry.java 2010-07-13
18:37:09 UTC (rev 18012)
@@ -37,7 +37,7 @@
*/
public final class QueueRegistry {
- public static final String QUEUE_SCRIPT_CLIENT_ID = "org.richfaces.queue";
+ public static final String QUEUE_SCRIPT_ID = "_org_richfaces_queue";
private static final Logger LOGGER = RichfacesLogger.COMPONENTS.getLogger();
Modified:
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/QueueResourceComponentRenderer.java
===================================================================
---
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/QueueResourceComponentRenderer.java 2010-07-13
18:31:23 UTC (rev 18011)
+++
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/QueueResourceComponentRenderer.java 2010-07-13
18:37:09 UTC (rev 18012)
@@ -80,8 +80,7 @@
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.ID_ATTRIBUTE, component.getClientId(context),
null);
writer.writeAttribute(HTML.TYPE_ATTR, HTML.JAVASCRIPT_TYPE, null);
writer.writeText(FUNCTION_NAME, null);
Modified:
root/ui/core/trunk/ui/src/test/java/org/richfaces/component/QueueRendererTest.java
===================================================================
---
root/ui/core/trunk/ui/src/test/java/org/richfaces/component/QueueRendererTest.java 2010-07-13
18:31:23 UTC (rev 18011)
+++
root/ui/core/trunk/ui/src/test/java/org/richfaces/component/QueueRendererTest.java 2010-07-13
18:37:09 UTC (rev 18012)
@@ -159,7 +159,7 @@
}
private String extractQueueScript(HtmlPage page) {
- HtmlElement scriptElement =
page.getElementById(QueueRegistry.QUEUE_SCRIPT_CLIENT_ID);
+ HtmlElement scriptElement = page.getElementById(QueueRegistry.QUEUE_SCRIPT_ID);
if (scriptElement != null) {
return getTextContent(scriptElement);
}
Show replies by date