Primefaces FileUpload with PrettyFaces 和 JSF 2.2.3 [英] Primefaces FileUpload with PrettyFaces and JSF 2.2.3

查看:36
本文介绍了Primefaces FileUpload with PrettyFaces 和 JSF 2.2.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 的页面上使用 PrettyFaces 时遇到了一些问题.

I'm having some problems with PrettyFaces on the pages I use <p:fileupload>.

当我禁用页面上的 PrettyFaces 过滤器时,一切正常.当我把它放回去时,我可以在网络浏览器上看到 HTTP 流量,但我的文件上传处理程序从未被触发.

When I disable the PrettyFaces filter on the page, everything works just fine. When I put it back, I can see the HTTP traffic on the webbrowser, but my fileupload handler is never fired.

这是代码的一些相关部分.

This is some relevant part of the code.

任何帮助将不胜感激!

我的 .xhtml

<h:form id="formImportarSNs" enctype="multipart/form-data">  
<p:fieldset legend="Admin Panel">    
   <p:fileUpload value="#{adminPanelBean.file}" mode="simple"/>                            
   <p:commandButton ajax="false" actionListener="#{adminPanelBean.upload}"            value="confirm" />  

</p:fieldset>  
</h:form>  

我的 backingBean

My backingBean

package br.sgrd.bean;  

import javax.annotation.PostConstruct;  
import javax.annotation.PreDestroy;  
import javax.faces.application.FacesMessage;  
import javax.faces.bean.ManagedBean;  
import javax.faces.bean.ViewScoped;  
import javax.faces.context.FacesContext;  

import org.primefaces.model.UploadedFile;  

@ViewScoped  
@ManagedBean  
public class AdminPanelBean{  

    private UploadedFile file;  

    public void upload() {    
        if(arquivo != null) {    
            FacesMessage msg = new FacesMessage("Succesful", file.getFileName() + "     is uploaded.");    
            FacesContext.getCurrentInstance().addMessage(null, msg);    
        }    
    } 

    // getters/setters/etc

}  

我的 web.xml

<?xml version="1.0" encoding="UTF-8"?>  
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns="http://java.sun.com/xml/ns/javaee"  
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee     http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"  
    version="3.0">  
    <display-name>GRD</display-name>      

    <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>/faces/*</url-pattern>  
    </servlet-mapping>             
    <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>  
        <url-pattern>/*</url-pattern>  
        <servlet-name>Faces Servlet</servlet-name>  
        <dispatcher>FORWARD</dispatcher>  
    </filter-mapping>   



</web-app>  

我的漂亮配置文件

<?xml version="1.0" encoding="UTF-8"?>  
<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces  
                      http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-    prettyfaces.xsd">  

    <url-mapping id="admin_panel">  
        <pattern value="/admin_panel" />  
        <view-id value="/faces/xhtml/admin_panel.xhtml" />  
    </url-mapping>  

</pretty-config> 

清理了一些代码.

推荐答案

我找到了解决方案.

在 META-INF 文件夹中创建 context.xml 并放置以下代码:

Create the context.xml in the META-INF folder and put this code:

<?xml version="1.0" encoding="UTF-8"?>
<Context allowCasualMultipartParsing="true">
</Context>

您可以从 web.xml

我在哪里找到了解决方案:http://ocpsoft.org/rewrite/docs/faq

Where I found the solution: http://ocpsoft.org/rewrite/docs/faq

这就是为什么你需要把它:如何在Tomcat上运行的servlet过滤器中使用HttpServletRequest#getParts()?

And that's why you need to put it: How to use HttpServletRequest#getParts() in a servlet filter running on Tomcat?

如果您的问题是文件的大小,请查看:<p:文件上传>限制为 2 Mb

If your problem is the size of the file, take a look at: <p:fileUpload> limiting to 2 Mb

这篇关于Primefaces FileUpload with PrettyFaces 和 JSF 2.2.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆