如何在 ICEfaces 中选择上传文件的文件名?
如何使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哦,我明白了。您不想调用 FileInfo.setFileName,而是调用 FileInfo.getFile().renameto()。
Oh, I got it. Instead of calling FileInfo.setFileName, you want to call FileInfo.getFile().renameto().