views:

28

answers:

1

How do you choose the filename of an uploaded file in ICEfaces with an ice:inputFile? The reason I want to do this is so that the user can upload multiple files with the same name, without them being overwritten by the server or causing an error.

I've tried setting the tag's submitOnUpload attribute to "preAndPostUpload" and making an uploadActionListener for that tag that changes the filename of the InputFile's FileInfo to a random string. If it tries to change the filename pre-upload, it gets ignored and the file is uploaded with the user-provided filename. If it tries to change the filename post-upload, I get a unhelpful NullPointerException. How do I choose the name the file is saved by?

JSF 1.2, IceFaces 1.8.2

+1  A: 

Oh, I got it. Instead of calling FileInfo.setFileName, you want to call FileInfo.getFile().renameto().

Nick