I'm using JSF 2.1 with JSP files. I tried to use JSF 2.1 with Facelet files, but didn't get Tomahawk (MyFaces extension) to work.
I'm trying to upload a file using Tomahawk. My form looks like follows:
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>FILE UPLOAD</title>
</head>
<body>
<fieldset>
<h:form enctype="multipart/form-data">
<t:inputFileUpload value="#{fileUploadBean.upFile}"
size="25"
required="true" /><br/>
<h:commandButton value="Validar" action="#{fileUploadBean.upload}" />
</h:form>
</fieldset>
</body>
</html>
</f:view>
and my bean is (as I'm using JSF 2.1, I don't need to use faces-config.xml
and I use annotations):
import java.io.IOException;
import java.io.InputStream;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.apache.myfaces.custom.fileupload.UploadedFile;
/**
*
* @author federico.martinez
*/
@ManagedBean
@RequestScoped
public class FileUploadBean {
private UploadedFile upFile;
public UploadedFile getUpFile(){
return upFile;
}
public void setUpFile(UploadedFile upFile){
this.upFile = upFile;
}
public String upload(){
InputStream is = null;
try {
is = upFile.getInputStream();
long size = upFile.getSize();
byte[] buffer = new byte[(int)size];
is.read(buffer,0,(int)size);
is.close();
System.out.println("File Upload Successful.");
return "processing-file";
} catch (IOException ex) {
Logger.getLogger(FileUploadBean.class.getName()).log(Level.SEVERE, null, ex);
return "error-lf";
} finally {
try {
is.close();
} catch (IOException ex) {
Logger.getLogger(FileUploadBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
Well that's it, but finally the problem is when I click on h:commandButton, it doesn't do anything. It seems like the method "upload" from my bean isn't working or something. what am I missing?