* @see org.apache.wicket.markup.html.IHeaderContributor#renderHead(org.apache.wicket.Response)
*/
public final void renderHead(final IHeaderResponse headResponse)
{
Response response = headResponse.getResponse();
final WebRequestCycle cycle = (WebRequestCycle)RequestCycle.get();
final IRequestTarget target = cycle.getRequestTarget();
IPageMap pageMap = webPage.getPageMap();
String name = pageMap.getName();
if (name == null)
{
name = "wicket:default";
}
else
{
name = name.replace('"', '_');
}
Session session = Session.get();
Session.PageMapAccessMetaData meta = (Session.PageMapAccessMetaData)session
.getMetaData(Session.PAGEMAP_ACCESS_MDK);
if (meta == null)
{
meta = new Session.PageMapAccessMetaData();
session.setMetaData(Session.PAGEMAP_ACCESS_MDK, meta);
}
boolean firstAccess = meta.add(pageMap);
if (firstAccess)
{
// this is the first access to the pagemap, set window.name
JavascriptUtils.writeOpenTag(response);
response
.write("if (window.name=='' || window.name.indexOf('wicket') > -1) { window.name=\"");
response.write(name);
response.write("\"; }");
JavascriptUtils.writeCloseTag(response);
}
else
{
// Here is our trickery to detect whether the current request
// was
// made in a new window/ tab, in which case it should go in a
// different page map so that we don't intermangle the history
// of
// those windows
CharSequence url = null;
if (target instanceof IBookmarkablePageRequestTarget)
{
IBookmarkablePageRequestTarget current = (IBookmarkablePageRequestTarget)target;
BookmarkablePageRequestTarget redirect = new BookmarkablePageRequestTarget(
session.createAutoPageMapName(), current.getPageClass(), current
.getPageParameters());
url = cycle.urlFor(redirect);
}
else
{
url = webPage.urlFor(INewBrowserWindowListener.INTERFACE);
}