Skip to content

Instantly share code, notes, and snippets.

@jonnywray
Created May 11, 2011 23:51
Show Gist options
  • Save jonnywray/967653 to your computer and use it in GitHub Desktop.
Save jonnywray/967653 to your computer and use it in GitHub Desktop.
Wicket decorator that uses jQuery to block the UI while an Ajax request completes
import org.apache.wicket.Component;
import org.apache.wicket.ajax.calldecorator.AjaxCallDecorator;
/**
* Ajax call decorator to block the page while the Ajax callback
* occurs.
*
* For some reason the jQuery plugin used for this decorator continues
* with a spinning wheel after the response is done until focus leaves
* the form component. Same thing happens on their web site. Find a better
* one if needed.
*
* @author Jonny Wray
*/
public class AjaxBlockUIDecorator extends AjaxCallDecorator{
private static final String BLOCK_SCRIPT_MESSAGE = "jQuery.blockUI({ message: '<h3>%s</h3>', overlayCSS: {opacity: .4 } });";
private static final String BLOCK_SCRIPT_NO_MESSAGE = "jQuery.blockUI({ message: null, overlayCSS: {opacity: .4 } });";
private static final String UNBLOCK_SCRIPT = "jQuery.unblockUI();";
private String message = null;
public AjaxBlockUIDecorator(){}
public AjaxBlockUIDecorator(String message){
this.message = message;
}
@Override
public CharSequence decorateScript(Component c, CharSequence script) {
return message == null ? BLOCK_SCRIPT_NO_MESSAGE + script : String.format(BLOCK_SCRIPT_MESSAGE, message) + script;
}
@Override
public CharSequence decorateOnSuccessScript(Component c, CharSequence script) {
return UNBLOCK_SCRIPT + script;
}
@Override
public CharSequence decorateOnFailureScript(Component c, CharSequence script) {
return UNBLOCK_SCRIPT + script;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment