Wednesday, August 24, 2011

Exit on ESC in Wicket ModalWindow


//Every modal dialog will extend this class
public class ModalPanelContainer extends ModalWindow implements IHeaderContributor {

//the magic is in this method
@Override
public void show(final AjaxRequestTarget target) {
if (!isShown()) {
final AppendingStringBuffer buffer = new AppendingStringBuffer(500);
buffer.append("function mwClose(ev) {\n" +
"var code = ev.keyCode || ev.which;\n" +
"if (code == 27) { " +
getCloseJavacript() +
"};" +
"}");
buffer.append("jQuery(document).keypress(mwClose);\n");
target.appendJavascript(buffer.toString());
}
super.show(target);
}



}

Custom 404 error page in Wicket

In web.xml you must have something like this:


WicketFilter
org.apache.wicket.protocol.http.WicketFilter


applicationClassName
com.yourproject.FrontendWebApplication



WicketFilter
/*
REQUEST
ERROR


404
/error404



After this create a page with mounting point "errror404".

That's it.