title: invoke confirmDialog in bean
body: <p>I use Primefaces 5.1 with JSF 2.2.6.</p>
  
  <p>i need identify if one file already exists in folder when user fileupload (primefaces).</p>
  
  <p>I have a class that uses PrimeFaces which uploads user files to a particular folder, but if the user attempts to upload a file with the same name as one that is already present i need alert and cancel the handler.</p>
  
  <p>Any idea?</p>
  
  <p>the code in xhtml is:</p>
  
  <pre><code>    &lt;h:form enctype="multipart/form-data" id="addFileDialog"&gt;
  
          &lt;p:fileUpload fileUploadListener="#{attachmentsComponent.handleFileUpload}" 
                        mode="advanced" multiple="true" dragDropSupport="true" 
                        label="#{text['tasksbacking.addFile.choose']}" uploadLabel="#{text['tasksbacking.addFile.upload']}"  cancelLabel="#{text['tasksbacking.addFile.cancel']}"
                        allowTypes="/(\.|\/)(gif|jpe?g|png|pdf|doc|docx|txt|xml)$/" invalidFileMessage="#{text['tasksbacking.addFile.invalidFile']}"
                        fileLimit="4" fileLimitMessage="#{text['tasksbacking.addFile.invalidCount']}"               
                        oncomplete="PF('addfile').hide();"/&gt;  
      &lt;/h:form&gt;
  </code></pre>
  
  <p>the code in bean is:</p>
  
  <pre><code>public void handleFileUpload(FileUploadEvent event) {
  
      // vars
      String originalName = event.getFile().getFileName();
      if (log.isDebugEnabled()) {
          log.debug("create file: " + originalName);
      }
      User loggedInUser = getSessionUser();
  
      // define parent folder
      Folder folder = null;
  
      // versionamento
      FileDetail fileDTSVersion = null;
  
      // verifica se ficheiro jÃ¡ existe na folder
      if (this.selectedNodeAttach != null) {
  
          if (this.selectedNodeAttach.getData() instanceof Attachment) {
              folder = (Folder) (this.selectedNodeAttach.getParent().getData());
          } else {
              folder = (Folder) (this.selectedNodeAttach.getData());
          }
          for (TreeNode tree : this.selectedNodeAttach.getChildren()) {
              if (tree.getType().equals("file")) {
                  Attachment fileChild = this.attachmentManager.initializeAttachment((Attachment) (tree.getData()));
  
                  if (fileChild.getName().equals(originalName)) {
                      if (fileChild.getContentObject() instanceof File) {
                          //file already exists --- need confirm action ???????????
                      }
                  }
              }
          }
      }
  
      // guarda ficheiro localmente 
      try {
          if (log.isDebugEnabled()) {
              log.debug("saving file in local..." + internalName);
          }
          copyFileToDisk(internalName, event.getFile().getInputstream());
      } catch (IOException ex) {
          log.error(null, ex);
      }
  }
  </code></pre>