package org.wicketTutorial.ajaxlistener;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.wicketTutorial.ajaxlistener.behavior.DisableComponentListener;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.wicketTutorial.commons.bootstrap.layout.BootstrapBasePage;
import org.apache.wicket.model.Model;
public class HomePage extends BootstrapBasePage {
private static final long serialVersionUID = 1L;
public HomePage(final PageParameters parameters) {
super(parameters);
final Form form = new Form("form");
form.add(new TextField("fakeField1", Model.of("")));
form.add(new TextField("fakeField2", Model.of("")));
form.add(new AjaxButton("ajaxButton"){
@Override
protected void onSubmit(AjaxRequestTarget target) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
attributes.getAjaxCallListeners().add(new DisableComponentListener(form));
}
});
add(form);
}
}