Updated Branches: refs/heads/master 5fde4b715 -> 983ecc70d
WICKET-4894 Internet Explorer fails fails to properly include conditional stylesheet links added via AjaxRequestTarget Add javadoc and a log warning explaining that IE conditional comments don't work in Ajax requests. Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/983ecc70 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/983ecc70 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/983ecc70 Branch: refs/heads/master Commit: 983ecc70df28ac40ce61299974617430b7530cbd Parents: 5fde4b7 Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Mon Dec 3 10:54:31 2012 +0100 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Mon Dec 3 10:54:31 2012 +0100 ---------------------------------------------------------------------- .../apache/wicket/markup/head/CssHeaderItem.java | 70 ++++++++++++++- 1 files changed, 68 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/983ecc70/wicket-core/src/main/java/org/apache/wicket/markup/head/CssHeaderItem.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/head/CssHeaderItem.java b/wicket-core/src/main/java/org/apache/wicket/markup/head/CssHeaderItem.java index 13e8abe..3af3d88 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/head/CssHeaderItem.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/head/CssHeaderItem.java @@ -16,12 +16,16 @@ */ package org.apache.wicket.markup.head; +import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.core.util.string.CssUtils; import org.apache.wicket.request.Response; +import org.apache.wicket.request.cycle.RequestCycle; import org.apache.wicket.request.mapper.parameter.PageParameters; import org.apache.wicket.request.resource.ResourceReference; import org.apache.wicket.util.lang.Args; import org.apache.wicket.util.string.Strings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Base class for all {@link HeaderItem}s that represent stylesheets. This class mainly contains @@ -31,9 +35,24 @@ import org.apache.wicket.util.string.Strings; */ public abstract class CssHeaderItem extends HeaderItem { + private static final Logger logger = LoggerFactory.getLogger(CssHeaderItem.class); + /** * The condition to use for Internet Explorer conditional comments. E.g. "IE 7". * {@code null} or empty string for no condition. + * + * <strong>Warning</strong>: the conditional comments don't work when injected dynamically + * with JavaScript (i.e. in Ajax response). An alternative solution is to use user agent sniffing + * at the server side: + * <code><pre> + * public void renderHead(IHeaderResponse response) { + * WebClientInfo clientInfo = (WebClientInfo) getSession().getClientInfo(); + * ClientProperties properties = clientInfo.getProperties(); + * if (properties.isBrowserInternetExplorer() && properties.getBrowserVersionMajor() >= 8) { + * response.renderCSSReference(new PackageResourceReference(MyPage.class, "my-conditional.css" )); + * } + * } + * </pre></code> */ private final String condition; @@ -95,7 +114,20 @@ public abstract class CssHeaderItem extends HeaderItem /** * Creates a {@link CssReferenceHeaderItem} for the given reference. - * + * + * <strong>Warning</strong>: the conditional comments don't work when injected dynamically + * with JavaScript (i.e. in Ajax response). An alternative solution is to use user agent sniffing + * at the server side: + * <code><pre> + * public void renderHead(IHeaderResponse response) { + * WebClientInfo clientInfo = (WebClientInfo) getSession().getClientInfo(); + * ClientProperties properties = clientInfo.getProperties(); + * if (properties.isBrowserInternetExplorer() && properties.getBrowserVersionMajor() >= 8) { + * response.renderCSSReference(new PackageResourceReference(MyPage.class, "my-conditional.css" )); + * } + * } + * </pre></code> + * * @param reference * a reference to a CSS resource * @param pageParameters @@ -131,6 +163,19 @@ public abstract class CssHeaderItem extends HeaderItem /** * Creates a {@link CssContentHeaderItem} for the given content. * + * <strong>Warning</strong>: the conditional comments don't work when injected dynamically + * with JavaScript (i.e. in Ajax response). An alternative solution is to use user agent sniffing + * at the server side: + * <code><pre> + * public void renderHead(IHeaderResponse response) { + * WebClientInfo clientInfo = (WebClientInfo) getSession().getClientInfo(); + * ClientProperties properties = clientInfo.getProperties(); + * if (properties.isBrowserInternetExplorer() && properties.getBrowserVersionMajor() >= 8) { + * response.renderCSSReference(new PackageResourceReference(MyPage.class, "my-conditional.css" )); + * } + * } + * </pre></code> + * * @param css * css content to be rendered. * @param id @@ -173,7 +218,20 @@ public abstract class CssHeaderItem extends HeaderItem /** * Creates a {@link CssUrlReferenceHeaderItem} for the given url. - * + * + * <strong>Warning</strong>: the conditional comments don't work when injected dynamically + * with JavaScript (i.e. in Ajax response). An alternative solution is to use user agent sniffing + * at the server side: + * <code><pre> + * public void renderHead(IHeaderResponse response) { + * WebClientInfo clientInfo = (WebClientInfo) getSession().getClientInfo(); + * ClientProperties properties = clientInfo.getProperties(); + * if (properties.isBrowserInternetExplorer() && properties.getBrowserVersionMajor() >= 8) { + * response.renderCSSReference(new PackageResourceReference(MyPage.class, "my-conditional.css" )); + * } + * } + * </pre></code> + * * @param url * context-relative url of the CSS resource * @param media @@ -195,6 +253,14 @@ public abstract class CssHeaderItem extends HeaderItem boolean hasCondition = Strings.isEmpty(condition) == false; if (hasCondition) { + if (RequestCycle.get().find(AjaxRequestTarget.class) != null) + { + // WICKET-4894 + logger.warn("IE CSS engine doesn't support dynamically injected links in " + + "conditional comments. See the javadoc of IHeaderResponse for alternative solution."); + } + + response.write("<!--[if "); response.write(condition); response.write("]>");
