It's common to want the user to confirm his action if it would be hard to reverse, e.g. if he asked to delete something. The confirmation can be easily obtained via a javascript confirm dialog box. If you'd rather not use javascript, another approach is outlined below.
Using Javascript
Wicket 6.x
This is a solution from Sven Meier for asking for confirmation on an AjaxLink in Wicket 6.x:Overwrite - 'overwrite #updateAjaxAttributes in your behavior or AjaxLink'. To make a reusable Component, simply create an abstract base class:
Code Block |
---|
public abstract class ConfirmationLink<T> extends AjaxLink<T> { private static final long serialVersionUID = @Override 1L; private final String text; public ConfirmationLink( String id, String text ) { super( id ); this.text = text; } @Override protected void updateAjaxAttributes( AjaxRequestAttributes attributes ) { { super.updateAjaxAttributes( attributes ); AjaxCallListener ajaxCallListener = new AjaxCallListener(); ajaxCallListener.onPrecondition( "return confirm('are you sure?" + text + "');" ); attributes.getAjaxCallListeners().add( ajaxCallListener ); } } } |
Earlier Wicket versions
Here's one way to do get confirmation, using Javascript:
...
Code Block |
---|
abstract public class ConfirmLink extends Link {
public ConfirmLink(String id, String msg) {
super(id);
add(new JavascriptEventConfirmation("onclick", "are you sure?"));
}
@Override
abstract public void onClick();
}
|
(The subclass could of course use SimpleAttributeModifier
instead.)
...