You'll need a combination of AbstractAjaxTimerBehaviour to raise an event that triggers an AjaxFormSubmittingBehaviour. I didn't try this but from my wicket experience and the JavaDocs of both behaviours, it should work.
Since there seems to be the need for some demo code...
Disclaimer: This was thrown together in a couple of minutes by Copy'n'Pasting from both mentioned classes. So this isn't good code, tested code or anything I'd put into production without having a solid look at it. But it seems to work.
First you need the combined Behavior:
public abstract class AjaxTimerFormSubmitBehavior extends AbstractAjaxTimerBehavior {
/**
* should never be accessed directly (thus the __ cause its overkill to
* create a super class), instead always use #getForm()
*/
private Form<?> __form;
private boolean defaultProcessing = true;
/**
* @param updateInterval
*/
public AjaxTimerFormSubmitBehavior(Duration updateInterval) {
this(null, updateInterval);
}
public AjaxTimerFormSubmitBehavior(Form<?> form, Duration updateInterval) {
super(updateInterval);
__form = form;
if (form != null) {
form.setOutputMarkupId(true);
}
}
@Override
protected void onTimer(final AjaxRequestTarget target) {
getForm().getRootForm().onFormSubmitted(new IFormSubmitter() {
public Form<?> getForm() {
return AjaxTimerFormSubmitBehavior.this.getForm();
}
public boolean getDefaultFormProcessing() {
return AjaxTimerFormSubmitBehavior.this.getDefaultProcessing();
}
public void onSubmit() {
AjaxTimerFormSubmitBehavior.this.onSubmit(target);
}
public void onError() {
AjaxTimerFormSubmitBehavior.this.onError(target);
}
});
}
/**
* @return Form that will be submitted by this behavior
*/
public final Form<?> getForm() {
if (__form == null) {
__form = findForm();
if (__form == null) {
throw new IllegalStateException(
"form was not specified in the constructor and cannot "
+ "be found in the hierarchy of the component this behavior "
+ "is attached to: Component="
+ getComponent().toString(false));
}
}
return __form;
}
/**
* @see Button#getDefaultFormProcessing()
*
* @return {@code true} for default processing
*/
public boolean getDefaultProcessing() {
return defaultProcessing;
}
/**
* Finds form that will be submitted
*
* @return form to submit or {@code null} if none found
*/
protected Form<?> findForm() {
// try to find form in the hierarchy of owning component
Component component = getComponent();
if (component instanceof Form<?>) {
return (Form<?>) component;
} else {
return component.findParent(Form.class);
}
}
/**
* Listener method that is invoked after the form has been submitted and
* processed without errors
*
* @param target
*/
protected abstract void onSubmit(AjaxRequestTarget target);
/**
* Listener method invoked when the form has been processed and errors
* occurred
*
* @param target
*/
protected abstract void onError(AjaxRequestTarget target);
}
And then you've got to use it
public class HomePage extends WebPage {
private static final long serialVersionUID = 1L;
private Integer counter = 0;
public HomePage(final PageParameters parameters) {
final Label label = new Label("counter", new PropertyModel<Integer>(this, "counter"));
label.setOutputMarkupId(true);
add(label);
Form form = new Form("form");
form.add(new AjaxTimerFormSubmitBehavior(form, Duration.seconds(10)) {
@Override
protected void onSubmit(AjaxRequestTarget target) {
counter++;
target.add(label);
}
@Override
protected void onError(AjaxRequestTarget target) {
// TODO Auto-generated method stub
}
});
add(form);
}
public Integer getCounter() {
return counter;
}
public void setCounter(Integer counter) {
this.counter = counter;
}
}
I hope that'll give you an idea...
Here is a small demo war-file. Just download, toss at your favorite Application Container and watch what it does. It contains the sources too.