我遇到版本4.0的<p:fileUpload>
问题,该文件永远不会在Bean中设置,并且永远不会调用监听器。我找到了许多解决方案,但它并没有解决我的问题
这是我的xhtml文件:
<h:form id="detailsDemandes" style="height:80%" enctype="multipart/form-data">
<p:focus context="detailsDemandes" />
<p:layout style="width:100%;height:80%;" id="layout">
<p:layoutUnit position="#{positionBean.pos}" resizable="true"
size="30%" style="height:100%">
<p:dataTable id="cars" var="car"
value="#{carController.beanList}" widgetVar="carsTable"
filteredValue="#{dtColumnsView.filteredCars}"
selectionMode="single" lazy="true"
selection="#{carController.selected}"
rowKey="#{not empty car.carId ? car.carId : car.hashCode() }">
<p:ajax event="rowSelect"
update=":demandeForm :detailsDemandes :formButton"
listener="#{carController.onSelectCar}" />
<p:ajax event="rowUnselect"
listener="#{carController.onUnselectCar}"
update=":demandeForm :detailsDemandes :formButton" />
<p:columns value="#{carController.columns}" var="column"
columnIndexVar="colIndex" sortBy="#{car[column.property]}"
filterBy="#{car[column.property]}">
<f:facet name="header">
<h:outputText value="#{column.header}" />
</f:facet>
<h:outputText value="#{car[column.property]}" />
</p:columns>
</p:dataTable>
<p:panelGrid style="width:70%;margin-left:4px">
<p:row>
<p:column styleClass="column" style="width:20%">
<p:fileUpload value="#{carController.file}" mode="advanced"
fileUploadListener="#{carController.fileUploadListener}">
</p:fileUpload>
</p:column>
<p:column styleClass="column" style="width:20%">
<p:graphicImage style="width:100px;" id="photo"
value="#{carController.image}">
</p:graphicImage>
</p:column>
</p:row>
</p:panelGrid>
</p:layoutUnit>
...
</p:layout>
我将此添加到我的web.XML:
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>auto|native|commons</param-value>
</context-param>
<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>Faces Servlet</servlet-name>
</filter-mapping>
我在pom.xml中添加了这些依赖项:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>