0

Problem with Messagebox

asked 2011-10-10 08:01:15 +0800

tomarts gravatar image tomarts
45 1

I am trying to make a delete action asking with a Messagebox if u want to delete but messagebox dont stop the excecution of the next code time and if i click on OK the first time dont eliminate but when i click on ok or cancel the second time it excecute it and the next action depends of the before answer that i was selected

I dont know what to do:

this is the code:

TO show Messagebox.QUESTION

private static int messageAnswer;

    public static boolean mensajePregunta(String mensaje) {
        try {
            int s = Messagebox.OK;
            int a = Messagebox.CANCEL;
            
            Messagebox.show("Realmente desea eliminar?", "", Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION, new EventListener() {

                @Override
                public void onEvent(Event event) throws Exception {
                    messageAnswer=((Integer) event.getData()).intValue();
                }
            });

           
            if (messageAnswer == s) {//<<<<<<---------------THIS LINE ALWAYS EXCECUTE EVEN IF MESSAGEBOX STILL SHOWED
                return true;
            } else {
                return false;
            }
        } catch (InterruptedException ex) {
            ex.printStackTrace();
            Logger.getLogger(ZKUtil.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }

Delete funtion

public void delete() {
        if (selected != null) {
            try {
                if (ZKUtil.mensajePregunta("Relamente desea elminarlo?")) {
                    crudService.delete(selected);
                    ZKUtil.mensaje("Eliminar", "Registro Eliminado");
                }
                buscar();
            } catch (Exception e) {
                e.printStackTrace();
                ZKUtil.mensajeError("No se pudo Elimiar");
            }
        } else {
            ZKUtil.mensajeError("Debe seleccionar Un elemento de la lista");
        }
    }

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2011-10-10 08:59:13 +0800

RichardL gravatar image RichardL
768 4

You could try this:

Messagebox.show("Are you sure you want to delete?", "Delete",
                                    Messagebox.OK | Messagebox.CANCEL, Messagebox.EXCLAMATION, new org.zkoss.zk.ui.event.EventListener() {

                                public void onEvent(Event e) throws Exception {
                                    if ("onOK".equals(e.getName())) {
                                       delete();
                                    }
                                }
                            });

link publish delete flag offensive edit

answered 2011-10-10 09:06:22 +0800

tomarts gravatar image tomarts
45 1

it could be but i use the function mensajePregunta(String mensaje) for make all questions in the program and will be a trouble.

link publish delete flag offensive edit

answered 2011-10-10 15:36:27 +0800

gyowanny gravatar image gyowanny
283 1 2 6

updated 2011-10-10 15:44:12 +0800

But the part that RicharL suggested (implementing an EventListener) will be implemented right at the time you call the Messagebox component.
So wherever you call it you may implement the event listener interface and call whatever you want.

A suggestion not tested:
Change your static method that calls the message box to be able to receive an EventListener implementation, like this:

public static boolean mensajePregunta(String mensaje, EventListener listener) {
   ......
   Messagebox.show(mensaje, "", Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION,listenert);
   ...
}

Then, call it as below:

    if (ZKUtil.mensajePregunta("Relamente desea elminarlo?", new EventListener(){  
                    public void onEvent(Event e) throws Exception {
                                    if ("onOK".equals(e.getName())) {
                                       delete();
                                       crudService.delete(selected);
                                       ZKUtil.mensaje("Eliminar", "Registro Eliminado");
                                    }
                     }
     });
                

Thanks,

Gyo

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-10-10 08:01:15 +0800

Seen: 171 times

Last updated: Oct 10 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More