0

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.

Angelika
  • 381
  • 1
  • 9
  • 22

2 Answers2

1

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(); 
            } 
        });
});
Moorthy GK
  • 1,283
  • 9
  • 17
1

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>  
Hatem Alimam
  • 9,968
  • 4
  • 44
  • 56
  • Another question please @Hatem, if I want to hide my download button again after downloding the file? – Angelika Feb 10 '14 at 10:24
  • 1
    Unfortunately the monitorDowonload's stop() would never be called due a bug in Primefaces.. see more http://stackoverflow.com/questions/20663551/js-function-not-triggered-with-primefaces-monitordownload – Hatem Alimam Feb 10 '14 at 10:43
  • When I try to add oncomplete="downloadWV.jq.hide()" in my download button , this button is not hidden – Angelika Feb 10 '14 at 11:46
  • Anyway the oncomplete won't trigger I think, because the button is already `ajax="false"` – Hatem Alimam Feb 10 '14 at 11:48
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/47167/discussion-between-angelika-and-hatem-alimam) – Angelika Feb 10 '14 at 12:05