Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

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 - '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 = 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('" + 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.)

...