package org.apache.wicket.examples.resourcedecoration;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AbstractAjaxTimerBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.examples.WicketExamplePage;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.markup.head.filter.FilteredHeaderItem;
import org.apache.wicket.markup.head.filter.FilteringHeaderResponse;
import org.apache.wicket.markup.head.filter.HeaderResponseContainer;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.CssResourceReference;
import org.apache.wicket.request.resource.JavaScriptResourceReference;
import org.apache.wicket.request.resource.PackageResourceReference;
import org.apache.wicket.resource.JQueryPluginResourceReference;
import org.apache.wicket.util.time.Duration;
@author
public class HomePage extends WicketExamplePage
{
private static final long serialVersionUID = 1L;
@param
public HomePage(final PageParameters parameters)
{
super(parameters);
final WebMarkupContainer jsPlaceholder = new WebMarkupContainer("jsProofPlaceholder");
jsPlaceholder.add(new Behavior()
{
private static final long serialVersionUID = 1L;
@Override
public void renderHead(Component component, IHeaderResponse response)
{
response.render(OnDomReadyHeaderItem.forScript("jQuery('#" +
jsPlaceholder.getMarkupId() +
"').html('the ondomready script ran').css('border-color', 'green');"));
}
});
add(jsPlaceholder);
add(new AjaxProofContainer("ajaxProofPlaceholder"));
add(new AbstractAjaxTimerBehavior(Duration.seconds(4))
{
private static final long serialVersionUID = 1L;
@Override
protected void onTimer(AjaxRequestTarget target)
{
HomePage.this.replace(new AjaxProofContainer("ajaxProofPlaceholder"));
target.add(HomePage.this.get("ajaxProofPlaceholder"));
stop(target);
}
});
add(new HeaderResponseContainer("footerJS", "footerJS"));
}
@Override
public void renderHead(IHeaderResponse response)
{
super.renderHead(response);
response.render(CssHeaderItem.forReference(new CssResourceReference(HomePage.class,
"footer.css")));
response.render(CssHeaderItem.forReference(new CssResourceReference(HomePage.class,
"header.css")));
response.render(CssHeaderItem.forReference(new CssResourceReference(HomePage.class,
"app.css")));
response.render(CssHeaderItem.forReference(new CssResourceReference(HomePage.class,
"HomePage.css")));
response.render(JavaScriptHeaderItem.forReference(new JQueryPluginResourceReference(
HomePage.class, "HomePage.js")));
response.render(new FilteredHeaderItem(
JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(HomePage.class,
"top.js")), FilteringHeaderResponse.DEFAULT_HEADER_FILTER_NAME));
}
private static class AjaxProofContainer extends WebMarkupContainer
{
private static final long serialVersionUID = 1L;
private AjaxProofContainer(String id)
{
super(id);
setOutputMarkupId(true);
}
@Override
public void renderHead(IHeaderResponse response)
{
if (getRequestCycle().find(AjaxRequestTarget.class).isPresent())
{
response.render(CssHeaderItem.forReference(new PackageResourceReference(
HomePage.class, "ajax.css")));
response.render(JavaScriptHeaderItem.forReference(new PackageResourceReference(
HomePage.class, "ajax.js")));
response.render(OnDomReadyHeaderItem.forScript("updatePending();"));
}
}
}
}