wicket.behavior
Class HeaderContributor

java.lang.Object
  extended by wicket.behavior.AbstractBehavior
      extended by wicket.behavior.AbstractHeaderContributor
          extended by wicket.behavior.HeaderContributor
All Implemented Interfaces:
java.io.Serializable, IBehavior, IHeaderContributor

public class HeaderContributor
extends AbstractHeaderContributor

A AbstractHeaderContributor behavior that is specialized on package resources. If you use this class, you have to pre-register the resources you want to contribute. A shortcut for common cases is to call forCss(Class, String) to contribute a package css file or forJavaScript(Class, String) to contribute a packaged javascript file. For instance:

 add(HeaderContributor.forCss(MyPanel.class, "mystyle.css"));
 

Author:
Eelco Hillenius
See Also:
Serialized Form

Nested Class Summary
static class HeaderContributor.CSSHeaderContributor
          Contributes a reference to a css file relative to the context path.
static class HeaderContributor.CSSReferenceHeaderContributor
          prints a css resource reference.
static class HeaderContributor.JavaScriptHeaderContributor
          Contributes a reference to a javascript file relative to the context path.
static class HeaderContributor.JavaScriptReferenceHeaderContributor
          prints a javascript resource reference.
static class HeaderContributor.ResourceReferenceHeaderContributor
          Wraps a ResourceReference and knows how to print a header statement based on that resource.
 
Constructor Summary
HeaderContributor()
          Construct.
HeaderContributor(IHeaderContributor headerContributor)
          Construct with a single header contributor.
 
Method Summary
 void addContributor(IHeaderContributor headerContributor)
          Adds a custom header contributor.
 void addContributor(int index, IHeaderContributor headerContributor)
          Adds a custom header contributor at the given position.
 void addCssReference(java.lang.Class scope, java.lang.String path)
          Adds a reference to a css file that should be contributed to the page header.
 void addJavaScriptReference(java.lang.Class scope, java.lang.String path)
          Adds a reference to a javascript file that should be contributed to the page header.
static HeaderContributor forCss(java.lang.Class scope)
          Deprecated. Will be removed in 2.0; contribute resources one by one instead
static HeaderContributor forCss(java.lang.Class scope, java.util.regex.Pattern pattern)
          Deprecated. Will be removed in 2.0; contribute resources one by one instead
static HeaderContributor forCss(java.lang.Class scope, java.util.regex.Pattern pattern, boolean recurse)
          Deprecated. Will be removed in 2.0; contribute resources one by one instead
static HeaderContributor forCss(java.lang.Class scope, java.lang.String path)
          Returns a new instance of HeaderContributor.CSSHeaderContributor with a header contributor that references a CSS file that lives in a package.
static HeaderContributor forCss(ResourceReference reference)
          Returns a new instance of HeaderContributor.CSSHeaderContributor with a header contributor that references a CSS file that lives in a package.
static HeaderContributor forCss(java.lang.String location)
          Returns a new instance of HeaderContributor.CSSHeaderContributor with a header contributor that references a CSS file that lives in the web application directory and that is addressed relative to the context path.
static HeaderContributor forJavaScript(java.lang.Class scope)
          Deprecated. Will be removed in 2.0; contribute resources one by one instead
static HeaderContributor forJavaScript(java.lang.Class scope, java.util.regex.Pattern pattern)
          Deprecated. Will be removed in 2.0; contribute resources one by one instead
static HeaderContributor forJavaScript(java.lang.Class scope, java.util.regex.Pattern pattern, boolean recurse)
          Deprecated. Will be removed in 2.0; contribute resources one by one instead
static HeaderContributor forJavaScript(java.lang.Class scope, java.lang.String path)
          Returns a new instance of HeaderContributor.CSSHeaderContributor with a header contributor that references a java script file that lives in a package.
static HeaderContributor forJavaScript(ResourceReference reference)
          Returns a new instance of HeaderContributor.CSSHeaderContributor with a header contributor that references a java script file that lives in a package.
static HeaderContributor forJavaScript(java.lang.String location)
          Returns a new instance of HeaderContributor.CSSHeaderContributor with a header contributor that references a JavaScript file that lives in the web application directory and that is addressed relative to the context path.
 IHeaderContributor[] getHeaderContributors()
          Gets the header contributors for this behavior.
 
Methods inherited from class wicket.behavior.AbstractHeaderContributor
cleanup, renderHead
 
Methods inherited from class wicket.behavior.AbstractBehavior
bind, detachModel, exception, onComponentTag, onException, onRendered, rendered
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HeaderContributor

public HeaderContributor()
Construct.


HeaderContributor

public HeaderContributor(IHeaderContributor headerContributor)
Construct with a single header contributor.

Parameters:
headerContributor - the header contributor
Method Detail

forCss

public static final HeaderContributor forCss(java.lang.Class scope)
Deprecated. Will be removed in 2.0; contribute resources one by one instead

Returns a new instance of HeaderContributor.CSSHeaderContributor with a set of header contributors that reference all CSS files with extension 'css' that live in a package.

Parameters:
scope - The scope of the package resource (typically the class of the caller, or a class that lives in the package where the resource lives).
Returns:
the new header contributor instance

forJavaScript

public static final HeaderContributor forJavaScript(java.lang.Class scope)
Deprecated. Will be removed in 2.0; contribute resources one by one instead

Returns a new instance of HeaderContributor.CSSHeaderContributor with a set of header contributors that reference all javascript files with extension 'js' that live in a package.

Parameters:
scope - The scope of the package resource (typically the class of the caller, or a class that lives in the package where the resource lives).
Returns:
the new header contributor instance

forCss

public static final HeaderContributor forCss(java.lang.Class scope,
                                             java.util.regex.Pattern pattern)
Deprecated. Will be removed in 2.0; contribute resources one by one instead

Returns a new instance of HeaderContributor.CSSHeaderContributor with a set of header contributors that reference CSS files that match the pattern and that live in a package.

Parameters:
scope - The scope of the package resource (typically the class of the caller, or a class that lives in the package where the resource lives).
pattern - The regexp pattern to match resources on
Returns:
the new header contributor instance

forCss

public static final HeaderContributor forCss(java.lang.Class scope,
                                             java.util.regex.Pattern pattern,
                                             boolean recurse)
Deprecated. Will be removed in 2.0; contribute resources one by one instead

Returns a new instance of HeaderContributor.CSSHeaderContributor with a set of header contributors that reference CSS files that match the pattern and that live in a package and its sub packages in case recurse is true.

Parameters:
scope - The scope of the package resource (typically the class of the caller, or a class that lives in the package where the resource lives).
pattern - The regexp pattern to match resources on
recurse - whether to recurse into sub packages
Returns:
the new header contributor instance

forJavaScript

public static final HeaderContributor forJavaScript(java.lang.Class scope,
                                                    java.util.regex.Pattern pattern)
Deprecated. Will be removed in 2.0; contribute resources one by one instead

Returns a new instance of HeaderContributor.CSSHeaderContributor with a set of header contributors that references java script files that match the pattern and that live in a package.

Parameters:
scope - The scope of the package resource (typically the class of the caller, or a class that lives in the package where the resource lives).
pattern - The regexp pattern to match resources on
Returns:
the new header contributor instance

forJavaScript

public static final HeaderContributor forJavaScript(java.lang.Class scope,
                                                    java.util.regex.Pattern pattern,
                                                    boolean recurse)
Deprecated. Will be removed in 2.0; contribute resources one by one instead

Returns a new instance of HeaderContributor.CSSHeaderContributor with a set of header contributors that references java script files that match the pattern and that live in a package and sub packages in case recurse is true.

Parameters:
scope - The scope of the package resource (typically the class of the caller, or a class that lives in the package where the resource lives).
pattern - The regexp pattern to match resources on
recurse - whether to recurse into sub packages
Returns:
the new header contributor instance

forCss

public static final HeaderContributor forCss(java.lang.Class scope,
                                             java.lang.String path)
Returns a new instance of HeaderContributor.CSSHeaderContributor with a header contributor that references a CSS file that lives in a package.

Parameters:
scope - The scope of the package resource (typically the class of the caller, or a class that lives in the package where the resource lives).
path - The path
Returns:
the new header contributor instance

forCss

public static final HeaderContributor forCss(ResourceReference reference)
Returns a new instance of HeaderContributor.CSSHeaderContributor with a header contributor that references a CSS file that lives in a package.

Parameters:
reference -
Returns:
the new header contributor instance

forCss

public static final HeaderContributor forCss(java.lang.String location)
Returns a new instance of HeaderContributor.CSSHeaderContributor with a header contributor that references a CSS file that lives in the web application directory and that is addressed relative to the context path.

Parameters:
location - The location of the css file relative to the context path
Returns:
the new header contributor instance

forJavaScript

public static final HeaderContributor forJavaScript(java.lang.Class scope,
                                                    java.lang.String path)
Returns a new instance of HeaderContributor.CSSHeaderContributor with a header contributor that references a java script file that lives in a package.

Parameters:
scope - The scope of the package resource (typically the class of the caller, or a class that lives in the package where the resource lives).
path - The path
Returns:
the new header contributor instance

forJavaScript

public static final HeaderContributor forJavaScript(ResourceReference reference)
Returns a new instance of HeaderContributor.CSSHeaderContributor with a header contributor that references a java script file that lives in a package.

Parameters:
reference -
Returns:
the new header contributor instance

forJavaScript

public static final HeaderContributor forJavaScript(java.lang.String location)
Returns a new instance of HeaderContributor.CSSHeaderContributor with a header contributor that references a JavaScript file that lives in the web application directory and that is addressed relative to the context path.

Parameters:
location - The location of the css file relative to the context path
Returns:
the new header contributor instance

addContributor

public final void addContributor(IHeaderContributor headerContributor)
Adds a custom header contributor.

Parameters:
headerContributor - instance of IHeaderContributor

addContributor

public final void addContributor(int index,
                                 IHeaderContributor headerContributor)
Adds a custom header contributor at the given position.

Parameters:
index - the position where the contributor should be added (e.g. 0 to put it in front of the rest).
headerContributor - instance of IHeaderContributor
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index > size()).

addCssReference

public final void addCssReference(java.lang.Class scope,
                                  java.lang.String path)
Adds a reference to a css file that should be contributed to the page header.

Parameters:
scope - The scope of the package resource (typically the class of the caller, or a class that lives in the package where the resource lives).
path - The path

addJavaScriptReference

public final void addJavaScriptReference(java.lang.Class scope,
                                         java.lang.String path)
Adds a reference to a javascript file that should be contributed to the page header.

Parameters:
scope - The scope of the package resource (typically the class of the caller, or a class that lives in the package where the resource lives).
path - The path

getHeaderContributors

public final IHeaderContributor[] getHeaderContributors()
Description copied from class: AbstractHeaderContributor
Gets the header contributors for this behavior.

Specified by:
getHeaderContributors in class AbstractHeaderContributor
Returns:
the header contributors; may return null if there are none
See Also:
AbstractHeaderContributor.getHeaderContributors()


Copyright © 2004-2007 Wicket developers. All Rights Reserved.