GWT : use Callback for interaction between UI components

Using GWT you create lot of UI components .And often these components have to interact with each other .Generally we should use some kind of message bus for interaction between the components those are not coupled to each other .But for the components where we have Parent – Child relationship ,In that case Child(callee) should interact with Parent(caller) using CallBack that Parent passed to it .

Suppose in online pizza shop you  order for pizza ,first  you enter your phone number ,application tries to find out your address by your phone number .If your address is not found ,it pop ups a window for you to enter address.Once address is entered application proceeds .Lets see how address pop interacts with its caller.

//callback interface

public interface AddressSubmitHandler {

       public void onAddressSubmit(Address address);


public class PizzaOrderPanel extends Composite{

      private Address address;

      private PizzaOrderService pizzaOrderService;

      public PizzaOrderPanel(){

          //if address is not found ,pop up a window and ask user to enter address

          new AddressPopup(new AddressSubmitHandler(){

                  public void onAddressSubmit(Address address){






public class AddressPopup extends PopupPanel {

      public AddressPopup(final AddressSubmitHandler addressSubmitHandler){

             //user have submitted address now call callback method




This entry was posted in GWT. Bookmark the permalink.

3 Responses to GWT : use Callback for interaction between UI components

  1. Alexey says:


    Thanks for your article. However, I can’t realize the method.
    Can you please program the following simple task:

    There is a button (A) on the page. Clicking on it invokes a dialog box prompting for a caption. After submitting original button (A) gets this caption.

    Thank you for response

    • DJ says:

      Hi Alexey, have you found an answer to the kind of question you’re asking ? I guess it’s for trying to reproduce something like the famous synchrone : “Window.confirm()” ? Am i wrong ?

      BTW, i’m curious the way to implement an easy way of having a “Window.confirm()” like in GWT ?

      Thanks a lot ! (Hope you (or someone else) will reply to my answer).

  2. Matthew says:

    The only solution I have found for creating a custom popup dialog to mimic the Window.confirm() method is to utilize a PopupPanel and add a CloseHandler to the popup panel. When the popup panel closes, you may then evaluate which button was pressed.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s