In fact I have found WiQuery dialog more helpful. I am sharing my code with
you; just to show my version of using the dialog. Not necessarily the best
way, but is working for me and very helpful.
(I HAVE DEVELOPED MY VERSION USING ERNESTO REINALDO'S ORIGINAL SUGGESTION
FOR DIALOG BOX CREATION, AND WITH ADDITIONAL INTERFACE STRUCTURE FOR MY OWN
PURPOSE.).
Please note that the Dialog creation class is part of interface which also
has methods used within extended classes; to be implemented in the
respective page classes when adding the dialog.
package mypackage;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.odlabs.wiquery.ui.dialog.AjaxDialogButton;
import org.odlabs.wiquery.ui.dialog.Dialog;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* Created by Chhaya-MX on 6/23/14.
*/
public interface MyDialogBox extends Serializable {
public static final long serialVersionUID = 1L;
public enum Btn{
YES,
NO,
RESET,
DEFAULT
}
public class MyDialogBoxWindow extends Dialog {
/**
*
*/
private static final long serialVersionUID = 1L;
public AjaxDialogButton YES;
public AjaxDialogButton NO;
public AjaxDialogButton RESET;
Map btnTitles = new HashMap();
//Note the window positioning as parameter to the constructor
public MyDialogBoxWindow(String propertyName, String title,
WindowPosition windowPosition) {
super(propertyName);
setTitle(title);
setMinHeight(200); //You can customize as input parameter or
have protected method to set (similar to setTitle above)
setMinWidth(800); //You can customize as input parameter or
have protected method to set (similar to setTitle above)
setModal(true);
setAutoOpen(false);
setPosition(windowPosition);
setButtonTitles();
YES = dialogYesButton(btnTitles.get(Btn.YES));
NO = dialogNoButton(btnTitles.get(Btn.NO));
RESET = dialogResetButton(btnTitles.get(Btn.RESET));
setButtons(YES, NO);
setOutputMarkupId(true);
}
public void setButtons(AjaxDialogButton... buttons) {
super.setButtons(buttons);
}
private AjaxDialogButton dialogYesButton(String title) {
if (null == title || title.trim().length() <= 0){
title = "Yes";
}
return new AjaxDialogButton(title) {
private static final long serialVersionUID = 1L;
@Override
protected void onButtonClicked(AjaxRequestTarget target) {
onConfirmation(target);
}
};
}
private AjaxDialogButton dialogNoButton(String title) {
if (null == title || title.trim().length() <= 0){
title = "No";
}
return new AjaxDialogButton(title) {
private static final long serialVersionUID = 1L;
@Override
protected void onButtonClicked(AjaxRequestTarget target) {
onCancel(target);
close(target);
}
};
}
private AjaxDialogButton dialogResetButton(String title) {
if (null == title || title.trim().length() <= 0){
title = "Reset";
}
return new AjaxDialogButton(title) {
private static final long serialVersionUID = 1L;
@Override
protected void onButtonClicked(AjaxRequestTarget target) {
//Implement ME...
}
};
}
public void onConfirmation(AjaxRequestTarget target) {
//Override ME
}
public void onCancel(AjaxRequestTarget target) {
//Override ME
}
protected void setButtonTitles(){
}
public void setBtnTitles(Map btnTitles) {
this.btnTitles = btnTitles;
}
}
}
Now in your wicket page/panel get MyDialogBox method. Check how you can
pass different WindowPosition constant to meet your requirements:
private void addConfirmationDialog(final DataGrid,
GridObject> grid) {
confirmationDialog = new
MyDialogBox.MyDialogBoxWindow("confirmationDialog", "Are you sure you want
to delete offender(s)?", Dialog.WindowPosition.TOP) {
/**
*
*/
private static final long serialVersionUID = 1L;
/* (non-Javadoc)
* @see
mypackage.MyDialogBox.MyDialogBoxWindow#setButtonTitles()
*/
@Override
protected void setButtonTitles() {
Map btnTitles = new
HashMap();
btnTitles.put(MyDialogBox.Btn.YES, "Confirm");
btnTitles.put(MyDialogBox.Btn.NO, "No");
setBtnTitles(btnTitles);
}
@Override
pu