Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PrimeFaces progressBar does not update status

Tags:

primefaces

I want hide a progressbar on PrimeFaces when the process are completed. I think that isn't necessary show the progressbar while the isn't working.

The html code:

<div class="container marketing" style="margin-top: 2%;">
                    <div class="row">
                        <div class="col-md-4">
                            <img class="img-circle" title="Pedir WD"
                                 width="60" height="60" border="0" style="display: block; margin: auto"/>
                            <h2 style="text-align: center !important">Arena 2</h2>
                            <center>
                                <p>Exportación del <strong>01/01/<h:outputLabel value="#{registroDriver.anoActual}"/>
                                    </strong> hasta el <h:outputLabel value="#{registroDriver.ahora}"/></p>
                                <p:commandButton value="Iniciar Petición" onclick="PF('pbAjax').start();
                                        PF('startButton2').disable();" widgetVar="startButton2" actionListener="#{registroDriver.gestionRS()}"/>
                            </center>
                        </div>
                    </div>
                </div>
                <div style="margin-top: 5%">
                    <p:poll interval="2" update="pgBar"/>
                    <p:progressBar id="pgBar" widgetVar="pbAjax" ajax="true" value="#{registroDriver.progress}" labelTemplate="{value} % - #{registroDriver.estadoActual}"
                                   global="false" styleClass="animated">
                        <p:ajax event="complete" listener="#{registroDriver.onComplete()}" update="growl, linkWD" oncomplete="PF('startButton2').enable();"/>
                    </p:progressBar>
                </div>
                <h:panelGrid id="linkWD" style="margin-top: 3%; display: block;">
                    <h:outputText value="#{correo.URL_LINK}" rendered="#{registroDriver.finProceso eq true}"/>
                </h:panelGrid>

The java code:

private Integer progress = 0;
private Integer porcentajeCompletado = 0;
private boolean controlProgreso = true;
private String estadoActual = "";
private boolean finProceso = false;

public void gestionRS() throws ClassNotFoundException, 
InstantiationException, IllegalAccessException, SQLException, 
IOException, FileNotFoundException, AddressException {
System.out.println("[Conectando ...]");
System.out.println("Registrando Driver JDBC/TERADATA ...");
Class.forName(JDBC_DRIVER_TERAD).newInstance();
Connection con = DriverManager.getConnection(DB_URL_TERAD, tUser, tPass);

fCopy.fileCopy(PATH_ACCDB_LIMPIA, "accdb", PATH_DESTINO);
fCopy.fileCopy(PATH_CABECERA_MAIL, "png", PATH_DESTINO);

this.porcentajeCompletado = 5; // Estamos al  5%
estadoActual = "Conexión establecida.";
System.out.println(this.progress);
this.controlProgreso = false;
String nombreArchivoAccess = "WD_" + fechaActual.fechaActual() + ".accdb";
File archivoAccess = new File(nombreArchivoAccess);
this.porcentajeCompletado = 5; // Estamos al 10%
System.out.println(this.progress);
this.controlProgreso = false;
Database db = DatabaseBuilder.open(archivoAccess);
RSet2Access rs2Acces = new RSet2Access();

rs2Acces.resultSetToAccess(rs1, archivoAccess, db);
this.porcentajeCompletado = 10; 
System.out.println(this.progress);
this.controlProgreso = false;
estadoActual = "Confeccionada rs1";

db.close();
con.close();

System.out.println("\n[Conexión Cerrada]");
this.tamanoBase = size.tamanoArchivo(nombreArchivoAccess);
System.out.println("\nArchivo " + nombreArchivoAccess + " generado correctamente (" + this.tamanoBase + ")");

try {
    zip.zipFiles(nombreArchivoAccess);
    this.porcentajeCompletado = 40; // Sumamos los 2 procesos 
    this.controlProgreso = false;

    // Subimos el ZIP al FTP
    ftp.uploadFile(zip.getNameSaveZIP());
    this.porcentajeCompletado = 5;
    this.controlProgreso = false;
    estadoActual = "Subiendo " + zip.getNameSaveZIP() + " al servidor ...";

    File fDel = new File(nombreArchivoAccess);
    String maniobra = fDel.getAbsolutePath();

    Thread.sleep(1500);
    fd.eliminarFicheroRaiz(maniobra);
    fd.eliminarFicheroRaiz(zip.getNameSaveZIP());
    this.porcentajeCompletado = 5;
    this.controlProgreso = false;
    estadoActual = "Eliminando archivos locales ...";

    // Enviamos el mail
    mail.enviarMail(zip.getNameSaveZIP());
    fd.eliminarFicheroRaiz("cabeceraNueva.png");
    this.porcentajeCompletado = 10;
    this.controlProgreso = false;
    estadoActual = "Proceso terminado";
} catch (Exception e) {
    e.printStackTrace();
}
finProceso = true;
onComplete();
}

The problem that I have are: The variable String of status that I add to % not update, only show the value in % (variable int). Is very interesting that the panelgrid on html code show when the progressbar finish (value = 100).

Thanks for all.

like image 735
Raul Serra Avatar asked Nov 27 '25 22:11

Raul Serra


1 Answers

Use async="true" on your p:commandButton. Without it it is "blocking" other Ajax requests since they are queued by default (async is false by default).

like image 130
Jasper de Vries Avatar answered Dec 02 '25 03:12

Jasper de Vries