我遇到<p:fileUpload>
不断收到java.lang.NullPointerException
的问题。
这是我的代码:
XHTML:
<h:form enctype="multipart/form-data">
<p:growl id="messages" showDetail="true" />
<p:fileUpload value="#{fileUploadView.file}" mode="simple"/>
<p:commandButton value="Submit" ajax="false" actionListener="#{fileUploadView.upload}"/>
</h:form>
fileUploadView.java
public class FileUploadView {
public String[] inFileString;
private UploadedFile file;
public UploadedFile getFile() {
return file;
}
public void setFile(UploadedFile file) {
this.file = file;
}
public void upload() throws IOException {
if (file != null) {
InputStream strumyk = file.getInputstream();
InputStreamReader is = new InputStreamReader(strumyk);
BufferedReader reader = new BufferedReader(is);
inFileString[0] = reader.readLine();
FacesMessage readStream = new FacesMessage(inFileString[0]);
FacesMessage message = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
}
我在这里做错了吗?