Java 从列表中删除一个上载的文件<;上传文件>;

Java 从列表中删除一个上载的文件<;上传文件>;,java,jsf,Java,Jsf,好的,我在ManagedBean中创建了一个“动作”,将图片添加到列表中,请看下面的我的动作: public void novaFoto(FileUploadEvent event) { uploadsFotos.add(event.getFile()); } 现在,我必须执行以下操作:当用户单击一个按钮(“删除图片”)时,我必须从列表中删除该图片,但是如果这不是一个FileUploadEvent,只是一个普通的ActionEvent,我如何获得UploadedFile

好的,我在ManagedBean中创建了一个“动作”,将图片添加到列表中,请看下面的我的动作:

public void novaFoto(FileUploadEvent event) {
        uploadsFotos.add(event.getFile());
    }
现在,我必须执行以下操作:当用户单击一个按钮(“删除图片”)时,我必须从列表中删除该图片,但是如果这不是一个FileUploadEvent,只是一个普通的ActionEvent,我如何获得UploadedFile

我的ideia是这样的(但是如果我用commandButton触发此操作,我如何传递FileUploadEvent):


这在一定程度上取决于您希望如何向用户呈现列表

如果使用datatable,则可以使用迭代变量来处理删除操作。以下是一个例子:

<h:dataTable value="#{fileBean.files}" var="file" id="files">                        
      <h:column>
           <h:inputText value="#{file.name}"/>

           <h:commandButton value="delete" action="#{fileBean.delete(file)}">
                          <f:ajax render="@form"/>
           </h:commandButton>
      </h:column>
</h:dataTable>
<h:dataTable value="#{fileBean.files}" var="file" id="files">                        
      <h:column>
           <h:inputText value="#{file.name}"/>

           <h:commandButton value="delete" action="#{fileBean.delete(file)}">
                          <f:ajax render="@form"/>
           </h:commandButton>
      </h:column>
</h:dataTable>
public void delete(UploadedFile file) {
        files.remove(file);
}