提问人:zesty_AKDoctor 提问时间:12/2/2022 更新时间:12/2/2022 访问量:60
Set/Get,函数外部的 null 值
Set/Get, null value outside of function
问:
我遇到了一个问题,我的文档的获取和设置似乎没有保存。我有一个下拉列表,用户可以在其中选择他们要上传的文档。我使用 ajax 侦听器来设置他们正在上传的文档,在 onDocChange() 中,它似乎设置了值,但后来它是 null。我该如何解决这个问题?谢谢!
-爪哇8 -Primefaces6
<h:panelGroup>
<p:fileUpload fileUploadListener="#{uploadDocHandler.upload}"
mode="advanced" dragDropSupport="false" update="messages"
allowTypes="/(\.|\/)(pdf|jpeg|png)$/" id="CDDACreditForm"
value="#{uploadDocument.CDDACredit}" />
<p:growl id="messages" showDetail="true" />
<!-- <h:outputText value="#{msg.other_credits_maxsize}"
styleClass="outputLabel" /> -->
</h:panelGroup>
private String document;
public String getDocument() {
return document;
}
public void setDocument(String document) {
this.document = document;
}
public void onDocChange() {
if (document != null && !"".equals(document)) {
setDocument(document);
System.out.println("What the current Document selected is: " + getDocument());
}
}
public void upload(FileUploadEvent event) {
FacesMessage msg;
// Get file from upload event
UploadedFile file = event.getFile();
System.out.println("File name of upload: " + event.getFile().getFileName());
try {
copyFile(event.getFile().getFileName(), file.getInputstream());
System.out.println("Current Document: " + getDocument());
// Checks if document from the drop down is selected.
if (document != null) {
msg = new FacesMessage("Success! ", event.getFile().getFileName() + " is uploaded.");
} else {
msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid", "Document is not selected.");
}
FacesContext.getCurrentInstance().addMessage(null, msg);
// System.out.println(msg);
} catch (IOException e) {
e.printStackTrace();
}
}
尝试将文档绑定到 this.setDocument(document) 尝试使用get/set创建一个变量currentDocument,并尝试将值存储在那里。
答: 暂无答案
评论