首页 > 解决方案 > Vaadin addSucceededListener

问题描述

我在 Vaadin 8 中有一个上传按钮,上面有一个 addSucceededListener 侦听器 - 关于它我不知道很多事情......而且我找不到这种类型的侦听器的太多信息。当我单击该按钮时,我想启动一个确认窗口 - 我用它实例化ConfirmButton cd = new ConfirmButton("Confirmare");并打开模式弹出窗口cd.openInModalPopup();

我的问题是弹出窗口->cd.openInModalPopup();仅在“选择文件”窗口打开后才显示,我必须选择一个文件。我的问题是如何先显示确认信息,并且只有在用户确认后,才打开“选择文件”窗口。

添加以下代码:

 <vaadin-upload button-caption="Incarc INDICATORI " _id="cmdIncarcRaportInd" :right></vaadin-upload>
public Upload getCmdIncarcRaportInd() {
        return cmdIncarcRaportInd;
    }
getCmdIncarcRaportInd().addSucceededListener(event -> {
                    
                    int NR_Raport=0;
                    String WBL ="";
                    WBL = getCheBL().getValue()?"B":"I";
                    
                    if(raport!=null) NR_Raport=Numeric.getValInt(raport.get("Nr. Raport"));
                    
                    if (NR_Raport==0) {
                        Notification notif = new Notification("Atentie",
                                "NR Raport incorect",
                                        Notification.Type.ERROR_MESSAGE);
                                notif.setDelayMsec(-1);
                                notif.show(Page.getCurrent());
                                return;
                    }
                    
                    int NR_RaportW = NR_Raport;

                    if(WBL.equals("B")) {
                        NR_RaportW=99;
                        
                        ConfirmButton cd = new ConfirmButton("Confirmare");
                        cd.misWinTitle = "Atentie MIS";
                        cd.misWinText = "Incarcati valori Base Line ? Daca exista deja, cele vechi se vor rescrie cu valorile noi. CONFIRMATI BASE LINE (DA / NU) ?";
                        cd.misButOK = "DA";
                        cd.misButCancel = "NU";
                        cd.setOkAction(()->{
                            
                            String raspuns="ok";
                            if(!receiver.getFile().getName().split("_")[0].equals(proiect.get("Prj cod"))) {
                                Notification notif = new Notification("Atentie", "Cod Proiect Incorect",
                                                Notification.Type.ERROR_MESSAGE);
                                        notif.setDelayMsec(-1);
                                        notif.show(Page.getCurrent());
                                        return;
                            }
                            try {
                                raspuns = Utility.getSomeData(receiver.getFile(), proiect, 99, themeDisplay);
                            } catch (IOException | SQLException e) {
                                raspuns=e.getMessage();
                            }
                            Notification notificare = new Notification("Atentie - Incarcare Base Line Indicatori",
                                    raspuns,
                                    Notification.Type.ERROR_MESSAGE);
                            notificare.setDelayMsec(-1);
                            notificare.show(Page.getCurrent());
                            incarcGrdIndicatori(prj_cod);
                            
                            receiver.uploadFinished(event);
                        });
                        cd.setCancelAction(()->{
                            
                        });             
                        
                        cd.openInModalPopup();
                    } else { 
                        String raspuns="ok";
                                            
    
                        if(!receiver.getFile().getName().split("_")[0].equals(proiect.get("Prj cod"))) {
                            Notification notif = new Notification("Atentie", "Cod Proiect Incorect",
                                            Notification.Type.ERROR_MESSAGE);
                                    notif.setDelayMsec(-1);
                                    notif.show(Page.getCurrent());
                                    return;
                        }
                        try {
                            raspuns = Utility.DoSomeStuff(receiver.getFile(), proiect, NR_RaportW, themeDisplay);
                        } catch (IOException | SQLException e) {
                            raspuns=e.getMessage();
                        }
                        Notification notificare = new Notification("Atentie - Incarcare Rap Indicatori",
                                raspuns,
                                Notification.Type.ERROR_MESSAGE);
                        notificare.setDelayMsec(-1);
                        notificare.show(Page.getCurrent());
                        
                        incarcGrdIndicatori(prj_cod);
                        
                        receiver.uploadFinished(event);
                    }
                    
            
                    
                    
                    
                });
        
//);
        
    }

标签: javavaadinvaadin8

解决方案


添加一个用户点击的普通按钮,然后只有在满足您的条件时才显示上传按钮?


推荐阅读