I want to upload an Excel file to a JBoss Server with JSF, so I used Tomahawk.
Here is the view:
<%@ taglib uri="http://myfaces.apache.org/extensions" prefix="x"%>
<h:form id="MF" enctype="multipart/form-data" >
<x:inputFileUpload id="fileupload" value="#{dataentryctl.minvoice}" storage="file" required="false" />
<h:commandButton id="Submit" type="button" action="#{invoiceentryctl.PersistData}" value="save"
onclick="revalidateF12();submitForm()" onkeydown="keyDownEvents(this)" />
</h:form>
Here is the controller/model:
package panaceaFACweb.FACCtlbean;
import org.apache.myfaces.custom.fileupload.UploadedFile;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class dataentryctl {
private UploadedFile minvoice;
public UploadedFile getMinvoice() {
return minvoice;
}
public void setMinvoice(UploadedFile minvoice) {
this.minvoice = minvoice;
}
public String PersistData() {
load();
return null;
}
public void load() {
ParseXLS parseXls = new ParseXLS();
try {
InputStream input = minvoice.getInputStream();
// ...
} catch (IOException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
}
}
I have the following JARs:
- tomahawk-1.1.9.jar
- commons-el-1.0.jar
- commons-logging-1.1.1.jar
- commons-fileupload-1.2.2-javadoc.jar
- commons-io-1.4.jar
Other JARs related to JSF are already there. Other JSP pages work fine.
I am getting a NullPointerException
on the line InputStream input = minvoice.getInputStream();
.