我们正在开发 JSF spring webflow Web应用程序,我们正在尝试使用 primefaces fileupload 小部件。 primefaces工作正常,小部件正确呈现。但是文件上载不起作用。从不调用backingbean FileUploadController中的handlefileupload函数。其他primefaces组件,例如按钮可以调用该bean中的函数,因此它可以正确初始化。下面你找到我们的配置。目前我们正在eclipse中开发并使用maven部署Web应用程序并直接在eclipse中使用jetty服务器运行应用程序。在tomcat上部署.war也没有用。
问题:
依赖
的web.xml
<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>
start.xhtml
<h:form id="mainForm" enctype="multipart/form-data" prependid="false" >
<p:fileUpload id="fileUp" fileUploadListener="#fileUploadController.handleFileUpload}"
description="Images" /></h:form>
FileUploadController.java
public void handleFileUpload(FileUploadEvent event) {
System.out.println("FileUpload Test");
FacesMessage msg = new FacesMessage("ok", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
豆-config.xml中
<bean id="fileUploadController" class="de.hsrm.mi.media.FileUploadController" scope="session"></bean>
提前致谢。我们希望有人可以帮助我们:)
答案 0 :(得分:2)
使用此过滤器
<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>Spring MVC Dispatcher Servlet</servlet-name>
</filter-mapping>
答案 1 :(得分:0)
存在错误,或者您从xhtml文件中将其复制错误
<h:form id="mainForm" enctype="multipart/form-data" prependid="false" >
<p:fileUpload id="fileUp" fileUploadListener="#fileUploadController.handleFileUpload}"
description="Images" /></h:form>
“fileUploadController.handleFileUpload}”之前缺少“{”:
<h:form id="mainForm" enctype="multipart/form-data" prependid="false" >
<p:fileUpload id="fileUp" fileUploadListener="#{fileUploadController.handleFileUpload}"
description="Images" /></h:form>