views:

555

answers:

2

Hi all,

I have a JSF form that needs to upload a file via an icon click (i.e. without showing the textfield/browse button of the file upload component). Is it possible to trigger the file-open dialog and uploading functionality of the upload component via some other component type?

A: 

No, the file upload dialog is meant to be pretty much unchangeable as a security feature.

Shrike
A: 

I don't think there's any other "off the shelf" component you could use to trigger the file-open dialog (which, after all, results from a <input type=file> written by the renderer).

However, if you're willing to develop your own renderer, it could write both the <input> and your icon's <img> (one right after the other). Give the <input> a css class that uses absolute positioning to place it on top of the <img> and reduces it's opacity to 0 (you could also set the cursor to 'pointer').

Now, when the user clicks on the icon, they're also clicking on the invisible input, which pops up your dialog.

(Now that I think of it, I'm almost positive you can do this without writing your own renderer by just applying the same kind of css to off the shelf components...)

violoncello