Rapazeada to precisando de uma ajuda aqui…
estou utilizando o Glassfish 3.0.1 no Debian Lenny para rodar uma aplicação em JSF.
O problema está no upload de arquivos que não está chamando o método, e está jogando os arquivos na pasta /tmp/ do servidor.
segue o código se alguém puder dar uma luz eu agradeço.
upload.xhtml
web.xml
<?xml version="1.0"?>
Facelets StarterKit
TesteUpload
javax.faces.DEFAULT_SUFFIX
.xhtml
facelets.REFRESH_PERIOD
2
facelets.DEVELOPMENT
true
javax.faces.STATE_SAVING_METHOD
client
com.sun.faces.validateXml
true
com.sun.faces.verifyObjects
true
richfaces
Faces Servlet
REQUEST
FORWARD
INCLUDE
ERROR
RichFaces Filter
richfaces
org.ajax4jsf.Filter
Ajax4jsf Filter
ajax4jsf
org.ajax4jsf.Filter
createTempFiles
false
maxRequestSize
20000000
Faces Servlet
javax.faces.webapp.FacesServlet
1
Faces Servlet
*.jsf
index.jsf
BASIC
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
classeUpload
upload.ClasseUpload
session
com.sun.facelets.FaceletViewHandler
ClasseUpload.java
package upload;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import org.richfaces.event.UploadEvent;
import org.richfaces.model.UploadItem;
public class ClasseUpload{
public void listener(UploadEvent evento) throws Exception{
UploadItem upload = evento.getUploadItem();
File arquivoUpload = null;
if(upload.isTempFile()){
String string[] = upload.getFileName().split("\\\\");
arquivoUpload = new File("\\home\\storage\\" + string[string.length -1]); // "\\home\\storage\\"
InputStream in = new FileInputStream(upload.getFile());
OutputStream out = new FileOutputStream(arquivoUpload);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}else{
ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write(evento.getUploadItem().getData());
}
}
}