Sunday, November 23, 2008

AJAXified Confirmation box - Wicket

I have a ajax version of the confirmation box which can be used for Ajax button or Ajax Links.

import org.apache.wicket.ajax.calldecorator.AjaxCallDecorator;

/**
* Javascript Confirmation box for ajax components.
* Can be used for confirmation before deletion of a record.
*
* @author Srikanth NT
*/
public class ConfirmationBoxAjaxRenderer extends AjaxCallDecorator {

/** Serial Version UID. */
private static final long serialVersionUID = 284826838568155159L;

/** Message to be desplayed in the confirm box. */
private String message;

/**
* Constructor.
* @param message Message to be shown in the confirm box.
*/
public ConfirmationBoxAjaxRenderer(final String message) {
super();
this.message = message;
}

/**
* @param script existing script around the component.
* @return modified string.
* @see org.apache.wicket.ajax.calldecorator.AjaxCallDecorator#decorateScript(java.lang.CharSequence)
*/
@Override
public CharSequence decorateScript(final CharSequence script) {
return "if(!confirm('" + message + "')) return false;" + script;
}

}


Enjoy !!!