Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 894019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:18:50+00:00 2026-05-15T14:18:50+00:00

I’m trying to create a modal confirmation dialog box. I’d like it to work

  • 0

I’m trying to create a modal confirmation dialog box. I’d like it to work like Window.confirm(""), where I can just call it, and get a boolean response.

My trouble is I’m not sure how to do it. I’m trying to use MVP in my application. Here is the code I have so far:

public class DialogBoxPresenter implements Presenter {

    public interface Display {

        Label getDialogText();

        Button getAffirmativeButton();

        Button getCancelButton();

        Widget asWidget();

        public void center();

        public void hide();

        public void setHeader(String text);
    }
    private Display display;
    private String header;
    private String dialogText;
    private String cancelButtonText;
    private String affirmativeButtonText;

    protected DialogBoxPresenter() {
    }

    public DialogBoxPresenter(Display display, String header, String dialogText, String cancelButtonText, String affirmativeButtonText) {
        this.display = display;
        this.header = header;
        this.dialogText = dialogText;
        this.cancelButtonText = cancelButtonText;
        this.affirmativeButtonText = affirmativeButtonText;

        bind();
    }

    public DialogBoxPresenter(Display display, String header, String dialogText) {
        this.display = display;
        this.header = header;
        this.dialogText = dialogText;
        this.cancelButtonText = "Cancel";
        this.affirmativeButtonText = "OK";

        bind();
    }

    private void bind() {

        this.display.getDialogText().setText(dialogText);
        this.display.getAffirmativeButton().setText(affirmativeButtonText);
        this.display.getCancelButton().setText(cancelButtonText);
        this.display.setHeader(header);

        addClickHandlers();

    }

    private void addClickHandlers() {
        this.display.getAffirmativeButton().addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                doAffirmative();
            }
        });

        this.display.getCancelButton().addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                doCancel();
            }
        });
    }

    private void doAffirmative() {
        //do something
        display.hide();
    }

    private void doCancel() {
        //do something
        display.hide();
    }

    public void init() {
        display.center();
    }

    @Override
    public void go(HasWidgets container) {
        container.clear();
        container.add(display.asWidget());
    }
}

and my view:

public class DialogBoxView extends DialogBox implements DialogBoxPresenter.Display {

    private Label dialogText;
    private Button affirmativeButton;
    private Button cancelButton;
    private VerticalPanel container;

    public DialogBoxView() {
        //init items
        dialogText = new Label();

        affirmativeButton = new Button();
        cancelButton = new Button();

        container = new VerticalPanel();

        setGlassEnabled(true);
        setAnimationEnabled(true);
        setModal(false);

        init();
    }

    private void init() {
        //add items
        container.add(dialogText);

        HorizontalPanel hp = new HorizontalPanel();
        hp.add(affirmativeButton);
        hp.add(cancelButton);

        container.add(hp);
        this.add(container);
    }

    @Override
    public Widget asWidget() {
        return this;
    }

    @Override
    public Label getDialogText() {
       return dialogText;
    }

    @Override
    public Button getAffirmativeButton() {
        return affirmativeButton;
    }

    @Override
    public Button getCancelButton() {
       return cancelButton;
    }

    @Override
    public void setHeader(String text) {
       this.setText(text);
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:18:51+00:00Added an answer on May 15, 2026 at 2:18 pm

    You’re not going to be able to have it work in exactly the same way as Window.confirm(). The problem is that all of the javascript in a web page runs in a single thread. You’ll notice that as long as a standard confirm dialog is open, the rest of the page goes dead. That’s because the one javascript thread is blocked, waiting for confirm() to return. If you were to create a similar method for your dialog, as long as it was waiting for that method to return no user generated events would be processed and so your dialog wouldn’t work. I hope that makes sense.

    The best you will be able to do is similar to what the GWT library does for RPC calls — the AsyncCallback interface. You could even reuse that interface yourself, or you might prefer to roll your own:

    public interface DialogCallback {
        void onOk();
        void onCancel();
    }
    

    Instead of Window.confirm(String), your method signature will be more like Dialog.confirm(String,DialogCallback). Then your dialog just keeps a reference to the callback that’s passed in, and where you have // do something in your code you make calls to onOk and onCancel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.