Solved: Getting Confirm dialog messages

asked 2011-12-18 08:42:22 +0800

pdavie gravatar image pdavie
97 3

updated 2011-12-18 09:04:59 +0800

I'm sure many of you have had the same issue- using the confirm dialog. Up until now, I've generally designed my UI's not need a visual "Do you really want to do that?" popup.

There is no information (that I can find in the forums), well I came up with an elegant solution, other than embedding lots of boiler plate code everywhere, that is quite simple to implement and does NOT require changes to the ZK event thread.

The idea is simple: call the confirm dialog with an instance of an interface to call back. The code is below.

The interface:

package net.flowspace.zk;

public interface ConfirmResponse
   public void onConfirmClick (String code, int button) ;

As you can see, it's pretty simple. The reason for the 'code' part of the call, is that you can have multiple dialogs on one composer, so to tell them apart, each confirm query has a unique code, you test against in your implementing confirmResponse method.

The call to the confirm dialog looks like this:

Confirm Dialog Library Method:

    * Because the ZK event queue is non-blocking by default we need to tell the receiver what confirm
    * question was answered, so for each confirm query a unique 'code' needs to be sent to the implementation
    * of ConfirmResponse.
    * @param code    - Unique code for the question being asked.
    * @param msg     - Text for the dialog box contents.
    * @param title   - Title for the confirm dialog popup window.
    * @param cnf     - Instance of ConfirmResponse to send results to.
   public static void confirm(final String code, final String msg, final String title, final ConfirmResponse cnf)

         Messagebox.show(msg, title, Messagebox.YES | Messagebox.NO, Messagebox.QUESTION, new EventListener()
               public void onEvent(Event e)
                  if (null == cnf)
                     Dialogs.alert ("Internal Problem: ConfirmResponse cannot be null!") ;
                     return ;

                  if (Messagebox.ON_YES.equals(e.getName()))
                     cnf.onConfirmClick(code, Messagebox.YES) ;
                     if (Messagebox.ON_NO.equals(e.getName()))
                        cnf.onConfirmClick(code, Messagebox.NO) ;

      catch (InterruptedException e)


This way, if you put the code above in some library, mine is in a class called Dialogs, in your composer that implements ConfirmResponse you can simply call this:

Calling the static method:

   Dialogs.confirm ("DELTHING", "Are you sure you want to delete this thing?", "Delete", this) ;

Then in your composer you'd have a method like this:

Receiving the results of the call in your composer:

   public void onConfirmClick(String code, int button)

      if (code.equals("DELTHING") && button == Messagebox.YES)
         // Delete your thing here.


I hope this is of some use to others.
Have a great Christmas, or whatever you choose to celebrate. :-)

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2013-05-02 23:17:14 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8

Great solution. Thank you very much. You saved my day.

link publish delete flag offensive edit

answered 2014-08-05 09:36:02 +0800

srigalamilitan gravatar image srigalamilitan

great Solution.. Thankss

link publish delete flag offensive edit

answered 2014-08-28 08:07:12 +0800

srigalamilitan gravatar image srigalamilitan

hii there.. i have an idea..check this link putracode.blogspot.com/2014/08/custom-button-zk-with-confirmation.html

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




Asked: 2011-12-18 08:42:22 +0800

Seen: 805 times

Last updated: Aug 28 '14

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