我使用<t:inputFileUpload>
在我的应用程序中上传文件。所选文件(表示为UploadedFile
对象)仅在表单提交时保存到其绑定(支持bean中的成员)。当我在我的UI中使用动态元素时,表单将被重新渲染而不提交。在这种情况下,值绑定是无效的,用户必须使用<t:inputFileUpload>
重新选择文件。UIComponent的访问值绑定
当然,这不是非常用户友好。即使没有提交,<t:inputFileUpload>
也会抛出ValueChangedEvent
,我想注册一个事件处理程序,将新值(即上传的文件)复制到值绑定(即支持bean的成员)中。因为我想允许多个文件上传,我有UploadedFile
对象的数组作为值结合,在JSF中引用这样的:
<ui:repeat value="#{bean.myFiles}" var="file">
<t:inputFileUpload
value = "#{file}"
storage = "file" />
</ui:repeat>
现在,我愿做这样的事情:
UploadedFile[] myFiles;
public void valueChangedHandler(ValueChangedEvent ev) {
UploadedFile file = (UploadedFile)ev.getNewValue();
UIComponent comp = ev.getComponent();
// This line is pseudocode - getValueBinding() is not available
UploadedFile bindingFile = (UploadedFile)comp.getValueBinding();
// Assigning the new value to the binding
bindingFile = file;
}
这是可能的吗?我还没有理解如何调用ValueBinding getValueBinding(String)
来使它像我想要的那样发生。
鉴于这是不可能的,是否有任何方法可以在不提交的情况下保留''组件的内容?动态重新呈现会影响上传组件周围的''组件。 –
您是否阅读并理解了答案? – BalusC
再次阅读我终于明白为什么即使保存是不可能的(因为它实质上是在用户未提交表单的情况下预先填充文件输入组件)。谢谢您的回答。不仅要知道它不起作用,而且要知道为什么。 –