title: Block UI after successful of fields verification
body: <p>I use a JSF 2.2 with a Primefaces 5.3. I have to create a form which will be work like this:</p>
  
  <p>After pushing a button:</p>
  
  <ul>
  <li>If all required fields are filled in, the page is blocked (due to the sending of data to the database) as long as the data are sent.</li>
  <li>If one of the required fields aren't filled in, the page isn't blocked.</li>
  </ul>
  
  <p>Could you tell me how can I do it?</p>
  
  <p>This is a xhtml page:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:pm="http://primefaces.org/mobile"
        xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"&gt;
      &lt;h:head&gt;&lt;/h:head&gt;
      &lt;h:body id="page"&gt;
  
          &lt;f:metadata&gt;
              &lt;f:viewAction action="#{loginController.start()}" /&gt;
          &lt;/f:metadata&gt;  
  
          &lt;p:growl id="messages" showDetail="true" /&gt;
  
          &lt;h:form&gt;
              &lt;p:panelGrid id="panel" columns="2" styleClass="ui-noborder" columnClasses="rightalign,leftalign"&gt;                      
                  &lt;p:outputLabel for="databaseName" value="Database name:" /&gt;
                  &lt;p:inputText id="databaseName" required="true" value="#{userDatabase.name}" /&gt;
                  &lt;p:outputLabel for="databaseFile" value="File:" /&gt;
                  &lt;p:fileUpload id="databaseFile" required="true" fileLimit="1" update="file messages" fileUploadListener="#{dataController.handleFileUpload}" mode="advanced" dragDropSupport="true" sizeLimit="1000000000" uploadLabel="Upload" cancelLabel="Delete" allowTypes="/(\.|\/)(txt|binetflow)$/" /&gt;              
                  &lt;h:panelGroup /&gt;
                  &lt;h:outputText id="fileDescription" value="#{dataController.fileName}" /&gt;                        
                  &lt;p:commandButton id="buttonSend" value="Send" update="messages" action="#{dataController.send()}" /&gt;                        
              &lt;/p:panelGrid&gt;
  
              &lt;p:blockUI block="page" trigger="buttonSend"&gt;
                  Sending of the data...              
              &lt;/p:blockUI&gt;            
  
          &lt;/h:form&gt;
  
      &lt;/h:body&gt;   
  &lt;/html&gt;
  </code></pre>
  
  <p>This is a CDI bean:</p>
  
  <pre><code>package com.system.controller;
  
  import java.io.Serializable;
  import java.util.logging.Logger;
  
  import javax.enterprise.context.RequestScoped;
  import javax.enterprise.inject.Produces;
  import javax.faces.application.FacesMessage;
  import javax.faces.context.FacesContext;
  import javax.faces.view.ViewScoped;
  import javax.inject.Inject;
  import javax.inject.Named;
  
  import org.primefaces.event.FileUploadEvent;
  import org.primefaces.model.UploadedFile;
  
  import com.system.model.UserDatabase;
  import com.system.service.DataService;
  
  @Named
  @ViewScoped
  public class DataController implements Serializable {
  
      private static final long serialVersionUID = 1383572529241805730L;
  
      public void handleFileUpload(FileUploadEvent event){
          uploadFile=event.getFile(); 
  
          FacesMessage message = new FacesMessage("Successful", event.getFile().getFileName() + " is uploaded.");
          FacesContext.getCurrentInstance().addMessage(null, message);        
      }
  
      public String getFileName(){
  
          if(uploadFile==null) return "";
          else return uploadFile.getFileName();               
      }
  
      public void send(){
  
          if(uploadFile==null){
  
              FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "The file isn't uploaded", "You should upload a file"));
          }
          else{
  
              //Sending the data to the database... (tha page should be blocked)
  
              try {
                  Thread.sleep(5000);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
  
              //After successful of sending the data, the page should be unlocked.
  
              FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "The data has been added.", ""));           
          }
      }
  
      @Named
      @Produces
      @RequestScoped
      private UserDatabase userDatabase=new UserDatabase();  
  
      @Inject
      private DataService dataService;
  
      @Inject
      private Logger log;
  
      private UploadedFile uploadFile;
  }
  </code></pre>
  
  <p>Of course the above code it works but the page is blocked every time when I push the button (even if the fields aren't filled in). I think I should use a <code>widgetVar</code> istead of a <code>trigger</code> in a <code>p:blockUI</code> component but I don't know how and maybe I'm wrong. The best way for me would be if I could block/unlock the page from the <code>send</code> method in the CDI bean but I don't know if it's possible and apart from that - this isn't necessary. Each way will be helpful for me.</p>