Problem disabling button on primefaces

Asked

Viewed 664 times

1

I am trying to realize a logic of effecting the export button excel is disabled by clicking the search button if the number of records is equal to zero. The problem is that the first time it works normal, but the second time the button is no longer rendered again.

<f:facet name="footer">
    <p:row>
        <p:column style="text-align: right" colspan="4">
            <p:commandButton id="bt_filtrar" value="#{lbl['BOTAO.FILTRAR']}" process="filtro" actionListener="#{propostaCartaoListBean.buscar}" update="tabela br_exportar"/>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            <p:commandButton id="bt_limpar" icon="botaoLimpar" title="#{lbl['BOTAO.LIMPAR']}"/>
            &nbsp;
            <p:commandButton id="bt_exportar" icon="botaoExcel" ajax="false" disabled="#{propostaCartaoListBean.lazyModel.rowCount == 0}" title="#{lbl['BOTAO.EXPORTAREXCEL']}">
                <p:dataExporter type="xls" target="tabela" fileName="propostaCartao" />  
            </p:commandButton>                                  
        </p:column>
    </p:row>
</f:facet>

This button is at the end of a panelGrid and above a datatable.

How to solve this problem of losing component rendering?

  • Try changing this: propostaCartaoListBean.lazyModel.rowCount == 0 by a new method in your Viewbean that does this test and places a breakpoint within this method. See what happens.

  • @I’ll test and warn you.

  • What is the HTML output of propostaCartaoListBean.lazyModel.rowCount == 0?

  • @Tiagocésaroliveira looking for now, when I compare returns true but records appear on dataTable.

  • @Ciganomorrisonmendez is very strange but the lazyModel.rowCount returns 0 but shows values in datatable

  • @Macario1983 It means it is not reliable. I recommend that the test be changed.

  • Any suggestions?

Show 2 more comments

1 answer

1

Staff a fellow worker presented me with a workable solution to this problem.

<p:commandButton id="bt_filtrar" value="#{lbl['BOTAO.FILTRAR']}" 
    process="filtro"
    actionListener="#{propostaCartaoListBean.buscar}"
    update="tabela" oncomplete="atualizaBtnExportar()"/>

<p:commandButton id="bt_exportar" icon="botaoExcel" ajax="false" title="#{lbl['BOTAO.EXPORTAREXCEL']}" disabled="#{propostaCartaoListBean.lazyModel.rowCount == 0}">
    <p:dataExporter type="xls" target="tabela" fileName="propostaCartao" />  
</p:commandButton>

<p:remoteCommand name="atualizaBtnExportar" update="bt_exportar"/>

When using this tag p:remoteCommand it does the redirect to process what I want.

That is how it updates when completing the action on the filter button and calls the component.

But in case any of your colleagues know, I think you have the processing level of ajax before, during and after ajax.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.