如何在 ICEfaces 中选择上传文件的文件名?

发布于 2024-09-12 16:46:33 字数 330 浏览 2 评论 0原文

如何使用ice:inputFile 在 ICEfaces 中选择上传文件的文件名?我想这样做的原因是用户可以上传多个具有相同名称的文件,而不会被服务器覆盖或导致错误。

我尝试将标签的submitOnUpload属性设置为“preAndPostUpload”,并为该标签创建一个uploadActionListener,将InputFile的FileInfo的文件名更改为随机字符串。如果它尝试更改上传前的文件名,它将被忽略并使用用户提供的文件名上传文件。如果它尝试在上传后更改文件名,我会收到无用的 NullPointerException。如何选择文件保存的名称?

JSF 1.2、IceFaces 1.8.2

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁与争疯 2024-09-19 16:46:33

哦,我明白了。您不想调用 FileInfo.setFileName,而是调用 FileInfo.getFile().renameto()。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文