If you want to have a button to download a file in icefaces you create a button like:

<ice:outputResource id=”printButton”
    resource=”#{controller.print}”
    attachment=”true” label=”Print…” type=”button”
    fileName=”report.pdf” mimeType=”application/pdf” />

and have the backing bean look like:

public Resource getPrint() {
    //assume we have created the PDF and read into a byte stream oStream
    return new ByteArrayResource(oStream.toByteArray());
}

The side-effect is that the backing bean is evaluated constantly which means you keep building the PDF file.

The other problem is if you don’t have anything to download, what do you do.  It turns out to be pretty simple: just return a null.  In that case the button will not even be displayed on the screen!

    if (data.size()==0) return null;