Author: nbelaevski
Date: 2008-08-06 11:34:57 -0400 (Wed, 06 Aug 2008)
New Revision: 9956
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxViewHandler.java
trunk/framework/impl/src/main/java/org/ajax4jsf/context/ViewResources.java
Log:
https://jira.jboss.org/jira/browse/RF-4083
https://jira.jboss.org/jira/browse/RF-4103
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxViewHandler.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxViewHandler.java 2008-08-06
15:34:52 UTC (rev 9955)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxViewHandler.java 2008-08-06
15:34:57 UTC (rev 9956)
@@ -213,7 +213,21 @@
ViewResources viewResources = new ViewResources();
- viewResources.setExtendedSkinningAllowed(true);
+ boolean extendedSkinningAllowed = true;
+ String skinningLevel = getInitParameterValue(context,
InternetResourceBuilder.CONTROL_SKINNING_LEVEL);
+ if (skinningLevel != null && skinningLevel.length() > 0) {
+ if (InternetResourceBuilder.BASIC.equals(skinningLevel)) {
+ extendedSkinningAllowed = false;
+ } else if (!InternetResourceBuilder.EXTENDED.equals(skinningLevel)) {
+ throw new IllegalArgumentException("Value: " + skinningLevel +
+ " of " + InternetResourceBuilder.CONTROL_SKINNING_LEVEL
+ + " init parameter is invalid! Only " +
InternetResourceBuilder.EXTENDED
+ + ", " + InternetResourceBuilder.BASIC + " can be used");
+ }
+ }
+
+ viewResources.setExtendedSkinningAllowed(extendedSkinningAllowed);
+
viewResources.setScriptStrategy(getInitParameterValue(context,
InternetResourceBuilder.LOAD_SCRIPT_STRATEGY_PARAM));
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/context/ViewResources.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/context/ViewResources.java 2008-08-06
15:34:52 UTC (rev 9955)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/context/ViewResources.java 2008-08-06
15:34:57 UTC (rev 9956)
@@ -22,6 +22,7 @@
package org.ajax4jsf.context;
import java.io.IOException;
+import java.io.StringWriter;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -79,8 +80,12 @@
private Object[] result = null;
+ private static final String EXTENDED_SKINNING_ON_NO_SCRIPTS_INFO_KEY =
ViewResources.class.getName() + "EXTENDED_SKINNING_ON_NO_SCRIPTS_INFO_KEY";
+
private static final InternetResource EXTENDED_SKINNING_ON_RESOURCE = new
InternetResourceBase() {
+ private final String RESOURCE_KEY = this.getClass().getName();
+
@Override
public void encode(FacesContext context, Object data)
throws IOException {
@@ -92,20 +97,25 @@
public void encode(FacesContext context, Object data,
Map<String, Object> attributes) throws IOException {
- ResponseWriter writer = context.getResponseWriter();
- writer.startElement(HTML.SCRIPT_ELEM, null);
-
- if (!attributes.containsKey(HTML.TYPE_ATTR)) {
- writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
+ Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
+ if (requestMap.get(RESOURCE_KEY) == null) {
+ ResponseWriter writer = context.getResponseWriter();
+ writer.startElement(HTML.SCRIPT_ELEM, null);
+
+ if (!attributes.containsKey(HTML.TYPE_ATTR)) {
+ writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
+ }
+
+ for (Map.Entry<String, Object> entry : attributes.entrySet()) {
+ writer.writeAttribute(entry.getKey(), entry.getValue(), null);
+ }
+
+ writer.writeText("window.RICH_FACES_EXTENDED_SKINNING_ON=true;", null);
+
+ writer.endElement(HTML.SCRIPT_ELEM);
+
+ requestMap.put(RESOURCE_KEY, Boolean.TRUE);
}
-
- for (Map.Entry<String, Object> entry : attributes.entrySet()) {
- writer.writeAttribute(entry.getKey(), entry.getValue(), null);
- }
-
- writer.writeText("window.RICH_FACES_EXTENDED_SKINNING_ON=true;", null);
-
- writer.endElement(HTML.SCRIPT_ELEM);
}
};
@@ -152,7 +162,7 @@
public static final String SKINNING_STYLES_PATH =
"/org/richfaces/renderkit/html/css/";
- private boolean extendedSkinningAllowed = true;
+ private boolean extendedSkinningAllowed;
private boolean processScripts;
@@ -322,6 +332,8 @@
renderKit = rkFactory.getRenderKit(context, context
.getViewRoot().getRenderKitId());
+ boolean scriptsOff = false;
+
processStyles = true;
processScripts = true;
useSkinning = false;
@@ -371,6 +383,7 @@
if (null != scriptStrategy) {
if (InternetResourceBuilder.LOAD_NONE
.equals(scriptStrategy)) {
+ scriptsOff = true;
processScripts = false;
} else if (InternetResourceBuilder.LOAD_ALL
.equals(scriptStrategy)) {
@@ -457,17 +470,46 @@
useSkinning = true;
}
- if (!ajaxRequest && useSkinning && extendedSkinningAllowed) {
- //skinning levels aren't dynamic, page-level setting cannot be changed
- //by AJAX request
- EXTENDED_SKINNING_ON_RESOURCE.encode(context, null);
- }
+ if (useSkinning && extendedSkinningAllowed) {
+ if (!ajaxRequest) {
+ if (!scriptsOff) {
+ //skinning levels aren't dynamic, page-level setting cannot be changed
+ //by AJAX request
+ EXTENDED_SKINNING_ON_RESOURCE.encode(context, null);
+ } else {
+
+ Map<String, Object> applicationMap =
context.getExternalContext().getApplicationMap();
+ if (applicationMap.get(EXTENDED_SKINNING_ON_NO_SCRIPTS_INFO_KEY) == null) {
+ //do it once per application life - strategies can be changed dynamically
+ ResponseWriter writer = context.getResponseWriter();
+ try {
+ StringWriter stringWriter = new StringWriter();
+ context.setResponseWriter(oldResponseWriter.cloneWithWriter(stringWriter));
+
+ EXTENDED_SKINNING_ON_RESOURCE.encode(context, null);
- if (processScripts) {
- InternetResource resource = resourceBuilder.createResource(null,
- "/org/richfaces/renderkit/html/scripts/skinning.js");
+ stringWriter.flush();
+
+ log.info("Extended skinning is on and NONE scripts loading strategy was
detected. " +
+ "Do not forget that one of " +
InternetResourceBuilder.SKINNING_SCRIPT + " or " +
+ InternetResourceBuilder.COMMON_FRAMEWORK_SCRIPT + " resources should be
presented " +
+ "on the page together with the following code: \n" +
stringWriter.getBuffer().toString() +
+ "\nfor extended level of skinning to work.");
+ } finally {
+ context.setResponseWriter(writer);
+ }
- resource.encode(context, null);
+ applicationMap.put(EXTENDED_SKINNING_ON_NO_SCRIPTS_INFO_KEY, Boolean.TRUE);
+ }
+ }
+ }
+
+ if (processScripts) {
+ InternetResource resource = resourceBuilder.createResource(null,
+ InternetResourceBuilder.SKINNING_SCRIPT);
+
+ resource.encode(context, null);
+ }
}
componentWriter.endDocument();
@@ -475,9 +517,7 @@
} catch (IOException e) {
throw new FacesException(e.getLocalizedMessage(), e);
} finally {
- if (oldResponseWriter != null) {
- context.setResponseWriter(oldResponseWriter);
- }
+ context.setResponseWriter(oldResponseWriter);
}
}
}