Class FilteringHeaderResponse
java.lang.Object
org.apache.wicket.markup.html.DecoratingHeaderResponse
org.apache.wicket.markup.head.filter.FilteringHeaderResponse
- All Implemented Interfaces:
Closeable
,AutoCloseable
,IHeaderResponse
- Direct Known Subclasses:
JavaScriptFilteredIntoFooterHeaderResponse
This header response allows you to separate things that are added to the IHeaderResponse into
different buckets. Then, you can render those different buckets in separate areas of the page
based on your filter logic. A typical use case for this header response is to move the loading of
JavaScript files (and inline script tags) to the footer of the page.
- Author:
- Jeremy Thomerson, Emond Papegaaij
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
A filter used to bucket your resources, inline scripts, etc, into different responses. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The default name of the filter that will collect contributions which should be rendered in the page's <head> -
Constructor Summary
ConstructorDescriptionFilteringHeaderResponse
(IHeaderResponse response) Constructor without explicit filters.FilteringHeaderResponse
(IHeaderResponse response, String headerFilterName, Iterable<? extends FilteringHeaderResponse.IHeaderResponseFilter> filters) Construct. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Mark Header rendering is completed and subsequent usage will be ignored.protected IHeaderResponse
decorate
(IHeaderResponse response) Decorate the given response used to get contents.static FilteringHeaderResponse
get()
final CharSequence
getContent
(String filterName) Gets the content that was rendered to this header response and matched the filter with the given name.void
render
(HeaderItem item) Renders the givenHeaderItem
to the response if none of its tokens has been rendered before.protected void
render
(HeaderItem item, List<HeaderItem> filteredItems) protected void
setFilters
(Iterable<? extends FilteringHeaderResponse.IHeaderResponseFilter> filters) Methods inherited from class org.apache.wicket.markup.html.DecoratingHeaderResponse
getRealResponse, getResponse, isClosed, markRendered, wasRendered
-
Field Details
-
DEFAULT_HEADER_FILTER_NAME
The default name of the filter that will collect contributions which should be rendered in the page's <head>- See Also:
-
-
Constructor Details
-
FilteringHeaderResponse
Constructor without explicit filters. Generates filters automatically for any FilteredHeaderItem. Any other contribution is rendered in the page's <head>- Parameters:
response
- the wrapped IHeaderResponse- See Also:
-
FilteringHeaderResponse
public FilteringHeaderResponse(IHeaderResponse response, String headerFilterName, Iterable<? extends FilteringHeaderResponse.IHeaderResponseFilter> filters) Construct.- Parameters:
response
- the wrapped IHeaderResponseheaderFilterName
- the name that the filter for things that should appear in the head (default Wicket location) usesfilters
- the filters to use to bucket things. There will be a bucket created for each filter, by name. There should typically be at least one filter with the same name as your headerFilterName
-
-
Method Details
-
setFilters
protected void setFilters(Iterable<? extends FilteringHeaderResponse.IHeaderResponseFilter> filters) -
get
- Returns:
- the FilteringHeaderResponse being used in this RequestCycle
-
render
Description copied from interface:IHeaderResponse
Renders the givenHeaderItem
to the response if none of its tokens has been rendered before.Automatically marks all item's tokens as rendered.
- Specified by:
render
in interfaceIHeaderResponse
- Overrides:
render
in classDecoratingHeaderResponse
- Parameters:
item
- The item to render.- See Also:
-
close
Description copied from interface:IHeaderResponse
Mark Header rendering is completed and subsequent usage will be ignored. If some kind of buffering is used internally, this action will mark that the contents has to be flushed out.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceIHeaderResponse
- Overrides:
close
in classDecoratingHeaderResponse
-
getContent
Gets the content that was rendered to this header response and matched the filter with the given name.- Parameters:
filterName
- the name of the filter to get the bucket for- Returns:
- the content that was accepted by the filter with this name
-
decorate
Decorate the given response used to get contents.- Parameters:
response
- response to decorate- Returns:
- default implementation just returns the response
-
render
-