How to wait for the action from MessageBox

31 views
Skip to first unread message

Jessie

unread,
Jan 11, 2008, 7:49:28 AM1/11/08
to GWT-Ext Developer Forum
Hi,

I have the following codes that will do something when a dialog box is
used.
Basically, it will check whether the form is dirty. If it is, then it
will prompt to inform the user that the form is dirty and to ask if he/
she wants to close the form. If she click yes, then the form will
close, if it is not... then it will not close ... but now... the
window seem to close without waiting for the user ... therefore... the
result will always false .... how can i wait for the answer from user?
i cannot put the return = false inside the callback function because
the void method cannot return a value....

thanks.

addDialogListener(new DialogListenerAdapter(){

boolean result = false;

public boolean doBeforeHide(LayoutDialog dialog) {


if (form.isDirty()){

MessageBox.confirm("Cancel", "You have done some jobs. Do you
really want to cancel the job?",
new MessageBox.ConfirmCallback() {

public void execute(String btnID) {

if (btnID.equalsIgnoreCase("yes")){
result = true;
}

}

});

return result;

}else
return true;
}

});

Abhijeet

unread,
Jan 13, 2008, 1:15:42 PM1/13/08
to GWT-Ext Developer Forum
I am not sure how to wait for the result of the confirm dialog. But
the code below may solve your problem "hide the dialog when the user
clicks yes". Do let me know if I have missed something:

public void showDialog() {
final LayoutDialog dialog = new LayoutDialog(new
LayoutDialogConfig(), null,
null, null, null, null);
dialog.setSize("400", "400");
dialog.addButton("hahaha");
dialog.show();

dialog.addDialogListener(new DialogListenerAdapter() {

// boolean result = false; // not needed

final LayoutDialog innerRef = dialog;

public boolean doBeforeHide(LayoutDialog dialog) {

if (true) // form.isDirty()
{
MessageBox.confirm("Close?", "Unsaved changes. Close really?",
new MessageBox.ConfirmCallback() {
public void execute(String btnID) {
if (btnID.equalsIgnoreCase("yes")) {
innerRef.purgeListeners();
innerRef.hide();
}

}
});

// return result;
return false;
}
else
return true;
}
});

alberto33

unread,
Jan 13, 2008, 1:52:19 PM1/13/08
to GWT-Ext Developer Forum
The code below show what I have been doing. In short you call the
method when you get a response back from the user... The problem with
this is that you have to implement this for each action that you want
to check for... i.e. logging out or performing another action that
will destroy your user changes. One way to shorten the code is to
extend the MessageBox class and do all the configuration up front. But
there is probably a better way to do this.... I would be interested in
hearing about other approaches.

private void showMessageBox() {
MessageBox.show(new MessageBoxConfig() {
{
setTitle("Confirm");
setMsg(ToolbarWidget.confirmMessage);
setButtons(MessageBox.YESNOCANCEL);
setCallback(new MessageBox.PromptCallback() {
public void execute(String btnId, String text)
{
if (ToolbarWidget.YES.equals(btnId)) {
doYesAction();
} else if (ToolbarWidget.NO.equals(btnId))
{
doNoAction();
}
}
});
}
});
}

private void doNoAction() {
}

private void do YesAction() {
}





Jessie

unread,
Jan 16, 2008, 3:06:48 AM1/16/08
to GWT-Ext Developer Forum
innerRef.purgeListeners();
innerRef.hide();

works for me

Thanks
Reply all
Reply to author
Forward
0 new messages