hi all
I used primefaces 2.2.1 and file upload component worked successfully.
I use this libraries for upload:
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-logging-1.1.1.jar
commons-el.jar
and my code :
<h:form enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{upload2.handleFileUpload2}" allowTypes="*.*;"/>
</h:form>
my fileuypload listener call and work fine but when I removed primefaces-2.2.1.jar file and add primefaces-3.0.M1.jar to my project, file upload listener not call.
can any body help me to solve this problem??
netbeans 6.9, jsf 2.0, glassfish 3.0
file upload listener not call in primefaces 3.0M1
show us how you are using using the fileupload component and the corresponding action handler in the bean. I'm using the upload component so may spot something
Primefaces version: 3.0-SNAPSHOT
JSF implementation: Mojarra 2.0.4
Server: Glassfish 3.1-beta
JSF implementation: Mojarra 2.0.4
Server: Glassfish 3.1-beta
Thanks for your attention.
my xhtml page:
bean code to remove uploaded file to the folder named "upload" :
web.xml page:
all of this work fine in primefaces 2.2.1 but not in 3.0M1
my xhtml page:
Code: Select all
<h:body>
<f:view>
<h:form enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{upload2.handleFileUpload2}" allowTypes="*.*;"/>
</h:form>
</f:view>
</h:body>
bean code to remove uploaded file to the folder named "upload" :
Code: Select all
public void handleFileUpload2(FileUploadEvent event) {
file = event.getFile();
String fileName = tempUploadFileFolder + file.getFileName();
File mailFile = new File(fileName);
ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
String newFileName = servletContext.getRealPath("") + File.separator + "upload" + File.separator + file.getFileName();
FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
try {
FileOutputStream fos = new FileOutputStream(new File(newFileName));
InputStream is = file.getInputstream();
int BUFFER_SIZE = 8192;
byte[] buffer = new byte[BUFFER_SIZE];
int a;
while (true) {
a = is.read(buffer);
if (a < 0) {
break;
}
fos.write(buffer, 0, a);
fos.flush();
}
fos.close();
is.close();
} catch (IOException e) {
}
}
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">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>primefaces.PUBLIC_CAPTCHA_KEY</param-name>
<param-value>6Ld7pMESAAAAAHd1VihJkqPUXAJVwU3Cghc8fzrq</param-value>
</context-param>
<context-param>
<param-name>primefaces.PRIVATE_CAPTCHA_KEY</param-name>
<param-value>6Ld7pMESAAAAAMhr5WSk5bcRrff8Y08NtDi8Buoq</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>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<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>
<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>512000</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>/upload</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/upload2.xhtml</welcome-file>
</welcome-file-list>
</web-app>
all of this work fine in primefaces 2.2.1 but not in 3.0M1
Nothing that obvious to me. What I can say is limit the allowtypes. It is probably not expecting a regex but a comma seperated list as in the examples.
also specify a mode as it looks like its required.
This works for me
and this is my abbreviated handler
also specify a mode as it looks like its required.
This works for me
Code: Select all
<p:fileUpload fileUploadListener="#{drivingSchoolManager.handleFileUpload}"
mode="advanced"
uploadLabel="#{i18n['upload']}"
update="pnl messages text"
sizeLimit="1000000"
oncomplete=""
allowTypes="png,gif,jpg" >
</p:fileUpload>
Code: Select all
public void handleFileUpload( FileUploadEvent event )
{
try
{
FacesMessage msg = new FacesMessage( "Succesful", event.getFile().
getFileName() + " is uploaded." );
UploadedFile file = event.getFile();
}
catch ( Exception ex )
{
log.error( ex.toString(), ex );
JsfUtil.addErrorMessage( ResourceBundle.getBundle( "/i18n" ).
getString( "data.save.failed" ) );
throw new FacesException( ex );
}
}
Primefaces version: 3.0-SNAPSHOT
JSF implementation: Mojarra 2.0.4
Server: Glassfish 3.1-beta
JSF implementation: Mojarra 2.0.4
Server: Glassfish 3.1-beta
Yes, 'm using
Code: Select all
<!-- <version>3.0-SNAPSHOT</version>-->
<version>3.0.M1</version>
Primefaces version: 3.0-SNAPSHOT
JSF implementation: Mojarra 2.0.4
Server: Glassfish 3.1-beta
JSF implementation: Mojarra 2.0.4
Server: Glassfish 3.1-beta
in file upload simple mode, my listener called and worked successfully.
this is my xhtml code:
and my bean code(i create "upload" folder in web folder to restore uploade files there):
but I have same problem in advanced mode.
this is my xhtml code:
Code: Select all
<h:form enctype="multipart/form-data">
<p:messages showDetail="true"/>
<p:fileUpload value="#{upload2.file2}" mode="simple" allowTypes="*.*"/>
<p:commandButton value="Submit" ajax="false"
action="#{upload2.testSimpleUpload()}"/>
</h:form>
Code: Select all
@ManagedBean
@RequestScoped
public class upload2 {
/** Creates a new instance of upload2 */
public upload2() {
}
private UploadedFile file2;
public UploadedFile getFile2() {
return file2;
}
public void setFile2(UploadedFile file2) {
this.file2 = file2;
}
public void testSimpleUpload()
{
ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
String newFileName = servletContext.getRealPath("") + File.separator + "upload" + File.separator + file2.getFileName();
// FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
// FacesContext.getCurrentInstance().addMessage(null, msg);
try {
FileOutputStream fos = new FileOutputStream(new File(newFileName));
InputStream is = file2.getInputstream();
int BUFFER_SIZE = 8192;
byte[] buffer = new byte[BUFFER_SIZE];
int a;
while (true) {
a = is.read(buffer);
if (a < 0) {
break;
}
fos.write(buffer, 0, a);
fos.flush();
}
fos.close();
is.close();
} catch (IOException e) {
}
}
}
-
- Information
-
Who is online
Users browsing this forum: No registered users and 35 guests