FileUploadRenderer#decode()有时不会被触发

时间:2013-11-04 14:23:17

标签: jsf file-upload jsf-2 primefaces

我有使用primefaces 4.0 + TomEE的问题,当我使用fileUpload primeface的组件奇怪的时候我使用它没有触发事件FileUploadRenderer#decode()。这很烦人,因为它可以毫无问题地工作,而且我不能得到任何类型的错误信息。

在我写完问题之后,我一直在阅读和测试How to use PrimeFaces p:fileUpload? Listener method is never invoked的解决方案,但没有成功。

请查看我的附加代码:

的web.xml

 <filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
    <init-param>
        <param-name>thresholdSize</param-name>
        <param-value>51200</param-value>
    </init-param>
    <init-param>
        <param-name>uploadDirectory</param-name>
        <param-value>C:\bin</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter>
    <filter-name>SecurityFilter</filter-name>
    <filter-class>es.mypackage.SecurityFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>SecurityFilter</filter-name>
    <url-pattern>/xhtml/*</url-pattern>
</filter-mapping>

XHTML

 <ui:composition xmlns="http://www.w3.org/1999/xhtml"
template="../layout/template.xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">

<ui:define name="menu">
    <h:form id="menuForm">
        <p:menu model="#{menuManager.menu}" />
    </h:form>
</ui:define>

<ui:define name="content">
    <h:form id="gestionFicherosForm">
        <p:growl id="messages" showDetail="true" />
        <p:panel header="Gestion De Ficheros">
            <h:panelGrid columns="2">
                <h:outputText value="Añadir ficheros:" />
                <p:fileUpload
                    fileUploadListener="#{gestionFicheros.handleFile1Upload}"
                    mode="advanced" dragDropSupport="true" auto="true" update="messages, ficherosSubidos"
                    invalidFileMessage="Tipo de archivo no permitido." label="Examinar..."
                    multiple="true"
                    allowTypes="/(\.|\/)(csv|xls|xlsx)$/" />
            </h:panelGrid>
        </p:panel>
        <br />
        ...
        </h:form>
  </ui:define>
</ui:composition>

支持豆

    @ManagedBean
    @ViewScoped
    public class GestionFicheros implements Serializable {
    ...
    public void handleFile1Upload(FileUploadEvent event) {
    if (files == null) {
        files = new ArrayList<File>();
    }
    files.add(new File(event.getFile(),TipoFichero.AYDEN));
    FacesMessage msg = new FacesMessage("Succesful", event.getFile()
            .getFileName() + " subido.");
    FacesContext.getCurrentInstance().addMessage(null, msg);
    logger.info("fichero "+event.getFile().getFileName()+" subido.");
    }
    ...

可能是干扰正常请求流程的安全过滤器吗?但有时候呢?

欢迎任何建议。

0 个答案:

没有答案