public abstract class CssHeaderItem extends HeaderItem
HeaderItems that represent stylesheets. This class mainly contains
factory methods.| Modifier | Constructor and Description |
|---|---|
protected |
CssHeaderItem(String condition) |
getDependencies, getProvidedResources, getRenderTokens, renderprotected CssHeaderItem(String condition)
public String getId()
public CssHeaderItem setId(String markupId)
markupId - an optional markup id for this header itemthis object, for method chainingpublic String getCondition()
public static CssReferenceHeaderItem forReference(ResourceReference reference)
CssReferenceHeaderItem for the given reference.reference - a reference to a CSS resourceCssReferenceHeaderItem for the given reference.public static CssReferenceHeaderItem forReference(ResourceReference reference, String media)
CssReferenceHeaderItem for the given reference.reference - a reference to a CSS resourcemedia - the media type for this CSS ("print", "screen", etc.)CssReferenceHeaderItem for the given reference.public static CssReferenceHeaderItem forReference(ResourceReference reference, PageParameters pageParameters, String media)
CssReferenceHeaderItem for the given reference.reference - a reference to a CSS resourcepageParameters - the parameters for this CSS resource referencemedia - the media type for this CSS ("print", "screen", etc.)CssReferenceHeaderItem for the given reference.public static CssReferenceHeaderItem forReference(ResourceReference reference, PageParameters pageParameters, String media, String condition)
CssReferenceHeaderItem for the given reference.
Warning: 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:
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" ));
}
}
reference - a reference to a CSS resourcepageParameters - the parameters for this CSS resource referencemedia - the media type for this CSS ("print", "screen", etc.)condition - the condition to use for Internet Explorer conditional comments. E.g. "IE 7".CssReferenceHeaderItem for the given reference.public static CssContentHeaderItem forCSS(CharSequence css, String id)
CssContentHeaderItem for the given content.css - css content to be rendered.id - unique id for the <style> element. This can be null, however in
that case the ajax header contribution can't detect duplicate CSS fragments.CssContentHeaderItem for the given content.public static CssContentHeaderItem forCSS(CharSequence css, String id, String condition)
CssContentHeaderItem for the given content.
Warning: 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:
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" ));
}
}
css - css content to be rendered.id - unique id for the <style> element. This can be null, however in
that case the ajax header contribution can't detect duplicate CSS fragments.condition - the condition to use for Internet Explorer conditional comments. E.g. "IE 7".CssContentHeaderItem for the given content.public static CssUrlReferenceHeaderItem forUrl(String url)
CssUrlReferenceHeaderItem for the given url.url - context-relative url of the CSS resourceCssUrlReferenceHeaderItem for the given url.public static CssUrlReferenceHeaderItem forUrl(String url, String media)
CssUrlReferenceHeaderItem for the given url.url - context-relative url of the CSS resourcemedia - the media type for this CSS ("print", "screen", etc.)CssUrlReferenceHeaderItem for the given url.public static CssUrlReferenceHeaderItem forUrl(String url, String media, String condition)
CssUrlReferenceHeaderItem for the given url.
Warning: 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:
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" ));
}
}
url - context-relative url of the CSS resourcemedia - the media type for this CSS ("print", "screen", etc.)condition - the condition to use for Internet Explorer conditional comments. E.g. "IE 7".CssUrlReferenceHeaderItem for the given url.protected final void internalRenderCSSReference(Response response, String url, String media, String condition)
Copyright © 2006–2021 Apache Software Foundation. All rights reserved.