[英]Primefaces File Upload Stop Working After I have added PrettyFaces
First of all, the technologies I am using Primefaces 6.1
, PrettyFaces 3.3.3
and Wildfly 11
. 首先,我正在使用Primefaces 6.1
, PrettyFaces 3.3.3
和Wildfly 11
。 I simply want to upload a file to my database with Primefaces <p:fileUpload>
component. 我只想使用Primefaces <p:fileUpload>
组件将文件上传到我的数据库。 Here is the code snippet I have used. 这是我使用的代码段。
<h:form>
<p:fileUpload fileUploadListener="#{imageopbean.uploadImage}" mode="advanced" auto="true" style="display:none;" oncomplete="uppicture()" styleClass="imageUploadButton" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" >
<f:attribute name="uniqueid" value="#{profileBean.theUser.userId}"/>
</p:fileUpload>
</h:form>
it was working before I have used PrettyFaces library. 在我使用PrettyFaces库之前,它一直在工作。 Now, it doesn't invoke the fileUploadListener
. 现在,它不会调用fileUploadListener
。 I have read this question and some other solutions. 我已经阅读了这个问题和其他一些解决方案。 But I can't make them work. 但是我不能让它们工作。 What am I doing wrong? 我究竟做错了什么? Here is the other parts of my code. 这是我代码的其他部分。 Thanks. 谢谢。
web.xml web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>primefaces.FONT_AWESOME</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>extranet</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_BUFFER_SIZE</param-name>
<param-value>2048576</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>2</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<filter>
<filter-name>primeFacesFileUploadFilter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>primeFacesFileUploadFilter</filter-name>
<servlet-name>facesServlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>loginFilter</filter-name>
<url-pattern />
</filter-mapping>
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
<dispatcher>ASYNC</dispatcher>
</filter-mapping>
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>commons</param-value>
</context-param>
<session-config>
<session-timeout>
60
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>login.xhtml</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/error-404.xhtml</location>
</error-page>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/login</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/login</location>
</error-page>
</web-app>
ImageBean.java ImageBean.java
@Named("imageopbean")
@RequestScoped
public class ImageBean implements Serializable {
@EJB
private ImageManager imageManager;
/**
*
* @param event
*/
public void uploadImage(FileUploadEvent event) {
System.out.println("UPLOAD WORK");
....
}
}
I have tried most of the filter combinations in web.xml and nothing has worked. 我已经尝试了web.xml中的大多数过滤器组合,但没有任何效果。 I have found this, 我发现了这个
and I have deleted everything that I inserted in web.xml
and pom.xml
. 并且我删除了在web.xml
和pom.xml
插入的所有内容。 Here is the solution again: 这里再次是解决方案:
1- Add enctype="multipart/form-data"
to your <h:fom>
tag 1-将enctype="multipart/form-data"
到您的<h:fom>
标记
2- Edit the script according to your JSF page 2-根据您的JSF页面编辑脚本
<script type="text/javascript">
$(document).ready(function() {
$("form[enctype='multipart/form-data']").attr("action","#{request.contextPath}/test/fileupload.xhtml");
});
</script>
Thats all.. 就这样..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.