-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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"); } }
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(); } } });
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
Asked: 2011-10-10 08:01:15 +0800
Seen: 171 times
Last updated: Oct 10 '11