Lock send button when no file upload has been performed

0

So folks, I have a fileUpload component of primefaces to upload files. It turns out that even with required="true", if the user clicks send without having uploaded any files the system sends.

 <p:fileUpload
     required="true"
     requiredMessage="Comprovante ou declaração de vínculo de trabalho: item obrigatório"
     fileUploadListener="#{comprovanteBean.uploadArquivoDespesaTransporte}" update="@form" 
     label="Arquivo" uploadLabel="Enviar" cancelLabel="Cancelar" 
     allowTypes="/(\.|\/)(gif|jpe?g|png|pdf)$/"
     invalidFileMessage="São permitidos apenas arquivos do tipo: jpeg, jpg, png, pdf)"
     sizeLimit="1048576"invalidSizeMessage="O tamanho máximo permitido é de 1 MB." 
     fileLimit="1">
</p:fileUpload>



<p:commandButton value="Enviar comprovantes" update="@form" ajax="false" action="#{comprovanteBean.finalizarInscricao()}">
    <f:param name="inscricaoFinalizada" value="true"/>
</p:commandButton> 

On the firstfaces site, their button is locked, but it does not activate when I upload it, and you can not even get their code: link

Does anyone have any idea how to not allow the user to sign up without sending this file ??

    
asked by anonymous 26.02.2018 / 21:27

1 answer

0

You can try to enable the submit button only if there is a successful upload. I think the simplest is to use a flag, initially set to true :

In XHTML:

<p:commandButton value="Enviar comprovantes" update="@form" ajax="false" action="#{comprovanteBean.finalizarInscricao()}" disabled="#{comprovanteBean.semArquivos}">
    <f:param name="inscricaoFinalizada" value="true"/>
</p:commandButton>

No Bean:

private boolean semArquivos = true;

public boolean isSemArquivos() {
    return this.semArquivos;
}

public boolean setSemArquivos(boolean semArquivos) {
    this.semArquivos = semArquivos;
}

public void uploadArquivoDespesaTransporte(FileUploadEvent event) {
    //Executar o seu método já existente
    setSemArquivos(getArquivos().isEmpty());
}
    
10.07.2018 / 18:29