gpt4 book ai didi

jsf - Fileupload fileUploadListener 仅在每秒按下一次按钮时调用

转载 作者:行者123 更新时间:2023-12-04 21:42:43 25 4
gpt4 key购买 nike

我正在尝试使用 primefaces 5.2 中的 fileupload 组件上传文件,但我发现 fileUploadListener 绑定(bind)的函数并不是每次都被调用。当我第一次按下上传按钮时会调用它,但第二次不会调用。当我第三次按下上传按钮时会调用它,但它不会在第四次时调用。以下是我的代码和设置。

Web.xml

<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>auto</param-value>
</context-param><filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>
org.primefaces.webapp.filter.FileUploadFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

XHTML

<composite:implementation>
<p:fieldset legend="#{cc.attrs.tittle}" id="transfile" styleClass="fieldset" style="width:60%">
<h:form enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{transferFRorzwBean.translate}"
dragDropSupport="false" mode="advanced" sizeLimit="100000"
allowTypes="/(\.|\/)(txt|csv)$/" immediate="true"
label="Open" uploadLabel="Translate"/>
</h:form>
</p:fieldset>
</composite:implementation>

Java 代码

@ManagedBean
@ViewScoped
public class TransferFRorzwBean implements Serializable {
private static final long serialVersionUID = 1L;
private UploadedFile file;

public void translate(FileUploadEvent event) {
this.file = event.getFile();
String filename = FilenameUtils.getName(file.getFileName());
uploadFileName = filename;
InputStream input = file.getInputstream();
String path = FacesContext.getCurrentInstance()
.getExternalContext().getRealPath("/Protected/upload");
OutputStream output = new FileOutputStream(new File(path, filename));

try {
IOUtils.copy(input, output);
} finally {
IOUtils.closeQuietly(input);
IOUtils.closeQuietly(output);
}
}
public UploadedFile getFile() {
return file;
}

public void setFile(UploadedFile file) {
this.file = file;
}

IDE:Eclipse Kepler 服务版本 1服务器:Tomcat 8.0 jar :commons-fileupload-1.3.1.jar,commons-io-2.4.jar,primefaces-5.2.jar我也尝试在 web.xml 中添加以下内容,但不起作用...

<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>

有人对这个问题有想法吗?

最佳答案

我通过在 java 中添加如下代码解决了我的问题:

event.getComponent().setTransient(false);

关于jsf - Fileupload fileUploadListener 仅在每秒按下一次按钮时调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30525241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com