O'Reilly logo

PrimeFaces Beginner's Guide by K. Siva Prasad Reddy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – using the FileDownload component

Let us see how we can use the FileDownload component:

  1. Create the FileDownload component:
    <p:dialog modal="true" widgetVar="statusDialog" header="File Download Status" draggable="false" closable="false" resizable="false">  
      <p:graphicImage value="/resources/images/ajax-loader.gif" />  
    </p:dialog> 
    
    <h:form>
      <p:commandButton id="downloadBtn" value="Download" ajax="false" onclick="PrimeFaces.monitorDownload(onDownloadStart, onDownloadStop)" icon="ui-icon-arrowthick-1-s">  
      <p:fileDownload value="#{userController.userPic}" />  
    </p:commandButton>
    
    </h:form> 
  2. Implement the JavaScript callback methods to show the dialog box when the download starts and close the dialog when the download completes:
    <script type="text/javascript"> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required