使用Java(Seam + JBoss)并且在尝试更新文件时遇到很多困难。
我正在使用Seam fileUpload标记,并将表单编码类型设置为“multipart / form-data”。但是,当我选择一个文件并提交表格时,我得到了一个例外。
表格代码如下:
<h:form id="registration" enctype="multipart/form-data">
<h:outputText value="#{messages['profile.title']}"/>
<fieldset>
<!-- s:decorate id="usernameDecorate" template="edit.xhtml" -->
<ui:define name="label">Name:</ui:define>
<h:inputText id="name" value="#{editProfileAction.editProfileFormData.name}" required="true">
<!-- a:support id="onblur" event="onblur" reRender="usernameDecorate"/ -->
</h:inputText>
<!-- /s:decorate -->
<!-- s:decorate id="usernameDecorate" template="edit.xhtml" -->
<ui:define name="label">Email:</ui:define>
<h:inputText id="email" value="#{editProfileAction.editProfileFormData.email}" required="true">
<!-- a:support id="onblur" event="onblur" reRender="usernameDecorate"/-->
</h:inputText>
<!-- /s:decorate -->
<ui:define name="label">#{messages['profile.fieldlabel.photo']}</ui:define>
<s:fileUpload id="file" name="file"
data="#{editProfileAction.editProfileFormData.data}"
contentType="#{editProfileAction.editProfileFormData.contentType}"
fileName="#{editProfileAction.editProfileFormData.filename}"
fileSize="#{editProfileAction.editProfileFormData.size}" />
<div class="buttonBox">
<h:commandButton id="saveButton" value="Save" action="#{editProfileAction.update}"/>
 
<s:button id="cancel" value="Cancel" view="/home.xhtml"/>
</div>
我得到的例外情况如下:
Exception during request processing:
Caused by java.lang.NullPointerException with message: ""
org.jboss.seam.web.MultipartRequestImpl.parseRequest(MultipartRequestImpl.java:391)
org.jboss.seam.web.MultipartRequestImpl.getParameterNames(MultipartRequestImpl.java:530)
org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:84)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
答案 0 :(得分:0)
NullPointerException
你应该学习指针。
某处你没有说Foo foo = new Foo()
。我打赌在堆栈跟踪下面还有3行会告诉我们在哪里。除非你自己打电话给org.jboss.seam.web.MultipartRequestImpl.parseRequest
。
答案 1 :(得分:0)
我们在这里使用richfaces上传:
<rich:fileUpload id="fileUpload"
progressLabel="Uploading"
maxFilesQuantity="10"
listHeight="90px"
listWidth="400px"
addControlLabel="Select"
noDuplicate="true"
fileUploadListener="#{someJavaHome.uploadFile}"
clearAllControlLabel="Clear"
uploadControlLabel="Add Files"
doneLabel="Done"
cancelEntryControlLabel="Cancel"
clearControlLabel="Clear"
transferErrorLabel="Oops! Upload didn't work out."
sizeErrorLabel="Cannot be bigger than 1MB">
</rich:fileUpload>
public void uploadFile(UploadEvent uploadEvent) throws IOException{
try {
if(uploadEvent == null){
return;
}
for (UploadItem uploadItem : uploadEvent.getUploadItems()) {
if(!this.uploadItems.contains(uploadItem)){
this.uploadItems.add(uploadItem);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}