当我上传图像7文件时,primefaces-4
没有为每个文件调用侦听器方法。有时,调用3或4次,根本没有。顺便说一句,如果我只测试主面,这是可以的。我也用omnifaces-1.7
<p:fileUpload allowTypes="/(.|/)(gif|jpe?g|png)$/" fileUploadListener="#{MyUploadBean.handleAttachment}"
id="attachment" mode="advanced" multiple="true" sizeLimit="3000000"
update="imageGrid"/>
MyUploadBean.java
public void handleProposalAttachment(FileUploadEvent event) {
UploadedFile uploadedFile = event.getFile();
String fileName = uploadedFile.getFileName();
System.out.println(fileName); <-- Here, I can see some uploaded file name.
}
web . xml
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>#{GuestPreferences.theme}</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>facelets.SKIP_COMMENTS</param-name>
<param-value>true</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>/faces/*</url-pattern>
</servlet-mapping>
<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>2147483647</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>No Cache Filter</filter-name>
<filter-class>org.omnifaces.filter.CacheControlFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>No Cache Filter</filter-name>
<servlet-name>Faces Servlett</servlet-name>
</filter-mapping>
<filter>
<filter-name>Faces Exception Filter</filter-name>
<filter-class>org.omnifaces.filter.FacesExceptionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Faces Exception Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<listener>
<listener-class>org.ace.java.web.common.BootStrap</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-beans.xml</param-value>
</context-param>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error/500.xhtml</location>
</error-page>
Lib and server is Jboss 7.1.1
commons-io-2.4.jar
commons-fileupload-1.3.jar
primefaces-4.0-20130910.075046-7.jar
portlet-2.0.0.jar
portlet-api-2.0-r12.jar
gmultipart-0.2.jar
omnifaces-1.7.jar
我试过了,它对所有文件都有效,没有问题。我认为你的问题是:你把<p:fileUpload>
和另一个标签以某种形式,试着把<p:fileUpload>
单独放在形式上,它的工作很好:)不要忘记更新fileUpload的表单和image的表单。试试吧,我等着看是否可以,如果不行,把整个页面