Pregunta

I'm working with Primefaces, Initially my button is disabled, after clicking on "Search" and waiting that a search() function is finished, the button "Download" must be enabled, I tried to do this :

<h:form id="myForm" method="post">
  <p:commandButton id="search" value="Search" action="#{myBean.search}"/>                         
  <p:commandButton id="download" value="Download" ajax="false"  onclick="PrimeFaces.monitorDownload(start, stop)"  style="display:none">  
        <p:fileDownload value="#{myBean.file}" />
  </p:commandButton>  
</h:form>

My JQuery code look like this :

$(document).ready(
    function(){
        $("#myForm:search").change()(
            function(){
                if ($(this).val()) {
                   document.getElementById("download").style.display='block'; 
                } 
            }
            );
    })

My button "Downalod" is always hidden and my jquery file is included in my xhtml page.

¿Fue útil?

Solución

You may try this.

<p:commandButton id="search" value="Search" 
                 action="#{myBean.search}"
                 oncomplete="downloadWV.jq.show()"/>                         
<p:commandButton id="download" 
                 widgetVar="downloadWV"
                 value="Download"
                 ajax="false"
                 onclick="PrimeFaces.monitorDownload(start, stop)"
                 style="display:none">  
    <p:fileDownload value="#{myBean.file}" />
</p:commandButton>  

Otros consejos

I think you have used .click() function(){} like this. I have change.. Please check the following

$(document).ready(
function(){
    $("#search").click(
        function(){
            if ($(this).val() != '') {
               $("#download").show(); 
            } 
        });
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top