Coming Up for Air

JSF RI Sandbox FileDownload Component Changes

Today I checked in a couple of changes to the RI Sandbox file download component that will make the component more flexible, and, therefore, more usable.

Before these changes, the only way the component could be used was with one of two "methods:" "inline" (e.g., a PDF embedded in the page), or "download" (which was a link with a text anchor). While this worked, it was pretty limiting. What if the page author wants the link to be a picture, or if he wants the file download to start from on onChange even handler? Before today, that wasn’t possible. Today, though, I committed support for child components, as well as support for creating an EL variable that can be used by any child components as they please.

With the first change, something like is now possible:

1
2
3
4
5
<risb:download method="download" mimeType="application/pdf"
    fileName="HelloWorld.pdf"
    data="#{testBean.pdf}">
    <h:graphicImage alt="Download" url="/download.jpg"/>
</risb:download>

which will render an anchor, using the the download.jpg image as its content, that will deliver the HelloWorld PDF to the client when clicked. (In theory, anything can be used inside <risb:download />, though I’ve only tested with text and images.)

But what if you want a dynamically generated image to be displayed? With the second change, this is now possible:

1
2
3
4
<risb:download mimeType="image/jpg" fileName="image.jpg"
    data="#{testBean.image}">
    <h:graphicImage url="#{downloadUrl}" width="250px" />
</risb:download>

This simple example will render an image on the page, pulling the contents of the image from TestBean.getImage, and should the user try to save the image, the filename defaults to "image.jpg."

If you don’t like the variable name downloadUrl or if it would clobber one already set, you can specify the name of the variable with the urlVar attribute:

1
2
3
4
<risb:download mimeType="image/jpg" fileName="image.jpg"
    urlVar="foo" data="#{testBean.image}">
    <h:graphicImage url="#{foo}" width="250px" />
</risb:download>

Fancy.

At IEC, we’re pretty excited about these changes. We’re using both the download and multi-file upload components in a couple of different high profile projects, which means that they’re stable enough for production, and they also get a good deal of real world scrutiny, resulting in changes like these above.

These changes can be picked up from the RI CVS HEAD branch.

Thoughts? Complaints? Suggestions?

Quotes

Sample quote

Quote source