Glassfish3.0.1
Netbeans6.9.1
JSF2.0
Mojarro-2.0.3-FCS (which is not quite the same as distributed with Netbeans6.9.1's Glassfish3.0.1)
Browsers: Firefox3.0.19, Chrome, same experience.
Mac OS X 10.5.8
The handleFileUpload method of my managed UploadBean registered as fileUploadListener is never called.
I have scoured these forums and elsewhere for solutions to similar reported problems without success:
FileUpload not working, Event not fired (PrimeFaces 2.0.0-RC on a Glassfish v3)
Issue 545: File Upload Growl and messages not working
File Upload Growl & Messages are not working for me (JSF 2.0 mojarra, Tomcat 6, IE6, Primefaces 2.0)
Here is (a simplified version of) my UploadBean without writing the file:
Code: Select all
@ManagedBean
@SessionScoped
public class UploadBean implements Serializable {
private static final Logger logger = Logger.getLogger(UploadBean.class.getName());
public UploadBean() {}
public void handleFileUpload(FileUploadEvent event) {
logger.info("handleFileUpload:"+event.getFile().getFileName());
ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
File result = new File(extContext.getRealPath("//WEB-INF//upload") + "//" + event.getFile().getFileName());
try {
String $message = event.getFile().getFileName() + " is uploaded.";
logger.info($message);
FacesMessage msg = new FacesMessage("Succesful", $message);
FacesContext.getCurrentInstance().addMessage(null, msg);
} catch (Exception e) {
e.printStackTrace();
//String $message = event.getFile().getFileName() + " is uploaded.";
String $message = "The files were not uploaded!";
logger.log(Level.WARNING,$message);
FacesMessage error = new FacesMessage();
FacesContext.getCurrentInstance().addMessage(null, error);
}
}
}
It was adapted from an example at: PPR multi-file upload with PrimeFaces 2.0 (3 Apr 2010). Also adapted from that example I have the following XHTML snippet:
Code: Select all
<h:form enctype="multipart/form-data" prependId="false">
<p:growl id="messages" showSummary="true" showDetail="true" />
<p:fileUpload fileUploadListener="#{uploadBean.handleFileUpload}"
update="messages"
sizeLimit="1073741824"
multiple="true"
label="choose"
allowTypes="*.jpg;*.png;*.gif;*.txt;*.pdf;"
description="Files"
/>
</h:form>
I've tried using a form without any attributes at all. No luck.
I've tried using mulitple=false. No luck.
I've tried calling with direct URL index.xhtml or with referral. No luck.
I've tried using regular h:messages instead of growl; makes no difference. I introduced the logger to catch entry into handleFileUpload, it is definitely not being called on Upload.
The Glassfish output window in Netbeans shows nothing on Upload.
I looked in the server.log under glassfish-3.0.1/glassfish/domains/domain1/logs/. Nothing.
Here is my web.xml (I've tried all sorts of different ordering of other web xml element, but always with the file upload filter first:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>
org.primefaces.webapp.filter.FileUploadFilter
</filter-class>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>/tmp/files</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/primefaces_resource/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>com.sun.faces.allowTextChildren</param-name>
<param-value>true</param-value>
</context-param>
</web-app>
By now truly exasperated with this , and very grateful for specific help to achieve file upload.
Webel.