Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. <h:form>
  2. <br/>
  3. <p:outputLabel for="botao-iniciar">Iniciar transferências:</p:outputLabel>
  4. <p:commandButton id="botao-iniciar" onclick="PF('pbAjax-1').start()"
  5. widgetVar="startButton" value="Iniciar" />
  6. <br/><br/>
  7. <p:separator />
  8.  
  9. <ui:repeat var="transf" value="#{transferenciaStatusMB.listaTransferencia}">
  10. <h:panelGrid style="width:100%">
  11. <p:outputLabel>Transferência ID: #{transf.id}</p:outputLabel>
  12.  
  13. <p:progressBar widgetVar="pbAjax-#{transf.id}" ajax="true"
  14. value="#{transferenciaStatusMB.getProgresso(transf)}"
  15. labelTemplate="{value}%" global="false" interval="1000" >
  16. <p:ajax event="complete"
  17. listener="#{transferenciaStatusMB.onComplete(transf)}" />
  18. </p:progressBar>
  19.  
  20. <p:commandButton widgetVar="cancelButton-#{transf.id}" value="Cancelar"
  21. actionListener="#{transferenciaStatusMB.cancelar(transf)}"
  22. oncomplete="PF('cancelButton-#{transf.id}').disable();" >
  23. </p:commandButton>
  24.  
  25. <p:separator />
  26. </h:panelGrid>
  27. </ui:repeat>
  28. </h:form>
  29.  
  30. // Simulate task (based on the Primefaces' showcase example):
  31. public Integer getProgresso(Transferencia transferencia) {
  32. if(transferencia.getProgresso() == null) {
  33. transferencia.setProgresso(0);
  34. } else {
  35. System.out.printf("Progress Transference ID %d: %d.n", transferencia.getId(), transferencia.getProgresso());
  36.  
  37. if(transferencia.getProgresso() < 100){
  38. transferencia.setProgresso(
  39. transferencia.getProgresso() + (int)(Math.random() * 35));
  40.  
  41. if(transferencia.getProgresso() > 100) {
  42. transferencia.setProgresso(100);
  43. }
  44. }
  45.  
  46. try {
  47. Thread.sleep(2000);
  48. } catch (InterruptedException e) {
  49. e.printStackTrace();
  50. }
  51. }
  52.  
  53. return transferencia.getProgresso();
  54. }
  55.  
  56. // Cancel a task:
  57. public void cancelar(Transferencia transferencia) {
  58. transferencia.setProgresso(null);
  59. System.out.println("Transferencia ID " + transferencia.getId() +" CANCELADA!");
  60. }
  61.  
  62. // After a task is completed:
  63. public void onComplete(Transferencia transferencia) {
  64. System.out.println("Transferencia ID " + transferencia.getId() +" FINALIZADA!");
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement