use of org.apache.wicket.markup.html.internal.HtmlHeaderContainer in project wicket by apache.
the class WebPage method validateHeaders.
/**
* Validate that each component which wanted to contribute to the header section actually was
* able to do so.
*/
private void validateHeaders() {
// search for HtmlHeaderContainer in the first level of children or deeper
// if there are transparent resolvers used
HtmlHeaderContainer header = visitChildren(new IVisitor<Component, HtmlHeaderContainer>() {
@Override
public void component(final Component component, final IVisit<HtmlHeaderContainer> visit) {
if (component instanceof HtmlHeaderContainer) {
visit.stop((HtmlHeaderContainer) component);
} else if (component instanceof TransparentWebMarkupContainer == false) {
visit.dontGoDeeper();
}
}
});
if (header == null) {
// the markup must at least contain a <body> tag for wicket to automatically
// create a HtmlHeaderContainer. Log an error if no header container
// was created but any of the components or behaviors want to contribute
// something to the header.
header = new HtmlHeaderContainer(HtmlHeaderSectionHandler.HEADER_ID);
add(header);
RequestCycle requestCycle = getRequestCycle();
Response orgResponse = requestCycle.getResponse();
try {
StringResponse tempResponse = new StringResponse();
requestCycle.setResponse(tempResponse);
// Render all header sections of all components on the page
AbstractHeaderRenderStrategy.get().renderHeader(header, null, getPage());
IHeaderResponse headerResponse = header.getHeaderResponse();
headerResponse.close();
CharSequence collectedHeaderOutput = tempResponse.getBuffer();
if (collectedHeaderOutput.length() > 0) {
reportMissingHead(collectedHeaderOutput);
}
} catch (Exception e) {
// just swallow this exception, there isn't much we can do about.
log.error("header/body check throws exception", e);
} finally {
this.remove(header);
requestCycle.setResponse(orgResponse);
}
}
}
Aggregations