localization - Vaadin ConfirmDialog changing the title


Question: 

I want to change the title "Confirm" of a ConfirmDialog to something in my language. I looked at this, but the code does not make sense to me since the show method in my vaadin addon is a static method and it appears to be impossible to show a dialog returned by the factory.

I used this code to wrap the dialog:

package com.xxx.dialog;

import org.vaadin.dialogs.ConfirmDialog;

import com.xxx.message.MessageByLocaleService;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;

public class DeleteDialog {
    private ConfirmDialog cd;

    public DeleteDialog(MessageByLocaleService messageByLocaleService) {
        cd = ConfirmDialog.getFactory()
                .create(messageByLocaleService.getMessage("caption.confirm"),
                "", "OK",  "Cancel", "");
    }

    public abstract static class MyListener {
        public abstract void receive();
    }

    public void show(UI ui, MessageByLocaleService messageByLocaleService, MyListener yes, MyListener cancel) {
        //this.setCaption(messageByLocaleService.getMessage("caption.confirm"));
        //this.setMessageLabel(new Label(messageByLocaleService.getMessage("caption.confirm")));
        cd.show(ui, messageByLocaleService.getMessage("confirm.delete"),
                new ConfirmDialog.Listener() {
                    private static final long serialVersionUID = 1L;

                    public void onClose(ConfirmDialog dialog) {
                        if (dialog.isConfirmed()) {
                            // Confirmed to continue
                            yes.receive();
                        } else {
                            // User did not confirm
                            cancel.receive();
                        }
                    }
                });
        }
}

I had this class DeleteDialog as extends ConfirmDialog for some time, that is why some of the attempts I made that are commented out don't make sense.




1 Answer: 

I managed to achieve my goal by setting a new default factory.

package com.xxx.dialog;

import org.vaadin.dialogs.ConfirmDialog;

import com.xxx.message.MessageByLocaleService;
import com.vaadin.ui.UI;

public class DeleteDialog {
    ConfirmDialog.Factory oldFactory;
    ConfirmDialog.Factory factory;

    public DeleteDialog(MessageByLocaleService messageByLocaleService) {
        oldFactory = ConfirmDialog.getFactory();
        factory = new ConfirmDialog.Factory() {

            private static final long serialVersionUID = 1L;

            @Override
            public ConfirmDialog create(String arg0, String arg1, String arg2, String arg3, String arg4) {
            ConfirmDialog cd = oldFactory.create(messageByLocaleService.getMessage("caption.confirm"),
                    "", messageByLocaleService.getMessage("message.ok"),
                      messageByLocaleService.getMessage("message.cancel"), null);
            cd.setMessage(messageByLocaleService.getMessage("confirm.delete"));
            return cd;
            }
        };
    }

    public abstract static class MyListener {
        public abstract void receive();
    }

    public void show(UI ui, MessageByLocaleService messageByLocaleService, MyListener yes, MyListener cancel) {

        ConfirmDialog.setFactory(factory);
        ConfirmDialog.show(ui, messageByLocaleService.getMessage("confirm.delete"),
                new ConfirmDialog.Listener() {
                    private static final long serialVersionUID = 1L;

                    public void onClose(ConfirmDialog dialog) {
                        if (dialog.isConfirmed()) {
                            // Confirmed to continue
                            yes.receive();
                        } else {
                            // User did not confirm
                            cancel.receive();
                        }
                    }
                });
        }
}
 

More Articles


Google Smart Home Action: Account linking successful, SYNC response sent by fulfillment with status code 200 but Google Home app reporting error

I am building a Google Smart Home action with fulfillment hosted on AWS as a lambda function in node.js with the node implementation for Google Smart Home actions, exposed via AWS API gateway and an external OAuth 2 provider serving as authorizer for API gateway. My fulfilment includes SYNC, QUERY a

payment processing - pylons/python

I'm building an application that eventually needs to process cc #s. I'd like to handle it completely in my app, and then hand off the information securely to my payment gateway. Ideally the user would have no interaction with the payment gateway directly.Any thoughts? Is there an easier way?

Magento Payment methods are not showing in checkout

I have a website in magento. iam using payment methods paypal, bank transfer and stripe. using multi store view(3)Except paypal remaning payment methods are not showing in checkout process. i dont know what to do. please help me any one,Thanks,


java - JFrame as a dialog

I want to customize the jframe and that frame should work like a joptionpane. which is relative with parent. can i do like this. if it is possible please any one help me.

Magento: Where does Magento 1.8 store payment method options in the database?

Where does Magento store payment method options in the database?I looked around and did not find it.

magento - How to get id of last purchase with multiple addresses?

I have a payment method that needs to be redirected to the page it like paypal, I can add a code block on the page of success but need to know if petido that was just completed was paid with my payment method, so I can redirect.Note: several people say it is not possible to redirect payments with mu


How to use API in actions-on-google

I have tried the following javascript code, using a railway API in aog for getting names of trains between 2 stations.train : function(conv,src,dst) {const options={ method:'GET', url : `https://api.railwayapi.com/v2/between/source/${src}/dest/${dst}/date/23-09-2018/apikey/<api_key>/`,

Integrate with RBS WorldPay Hosted Payment Page (XML Redirect) using Python

Does anyone have any example code for integrating with RBS WorldPay using Python? Specifically posting the XML order to WorldPay

c# passing cookies as a parameter in sql

I am trying to save cookies on a login page pass it to another page where it will be used as a parameter in sql.saving cookies and redirecting to new page;HttpCookie cookie = new HttpCookie("UserID");cookie["UserID"] = reader["UserID"].ToString();Response.Cookies.Add(cookie);Response.Redirect("Home.

azure CloudBlobDirectory.ListBlobs() returns "The specified resource does not exist.", but fetchAttributes() works using same data

I am getting a "The specified resource does not exist" exception when I try to iterate the result of a ListBlobs() call. I can get the blob attributes when I access it directly, but I'm trying to get a list of all the blobs in the subdirectory.I wrote this little test to see exactly where the probl