Java 在Oracle ADF中文件上载期间,在Inputfile的valuechangelistener之外无法访问值
我正在Oracle ADF中创建一个表单,其中我使用inputfile将文件上载到db。当我通过输入文件选择一个文件时,ValueChangeListener会接收到该文件值,但如果我试图通过公共变量或getter访问ValueChangeListener函数之外的值,setter函数会接收到空值Java 在Oracle ADF中文件上载期间,在Inputfile的valuechangelistener之外无法访问值,java,jsf,file-upload,oracle-adf,valuechangelistener,Java,Jsf,File Upload,Oracle Adf,Valuechangelistener,我正在Oracle ADF中创建一个表单,其中我使用inputfile将文件上载到db。当我通过输入文件选择一个文件时,ValueChangeListener会接收到该文件值,但如果我试图通过公共变量或getter访问ValueChangeListener函数之外的值,setter函数会接收到空值 // Value Change Listener for inputFileComponent public void onFileUploadVCL(ValueChangeEvent val
// Value Change Listener for inputFileComponent
public void onFileUploadVCL(ValueChangeEvent valueChangeEvent) {
file=(UploadedFile)valueChangeEvent.getNewValue();
// get the file name
uploadedFileName=file.getFilename();
// get the mime type
contentType = file.getContentType();
// get blob
blob=getBlob(file);
}
//submit function where i need to use values
public void onSubmit(ActionEvent actionEvent) {
// Add event code here...
System.out.println("String:"+inEmpCode+"#"+outDesignation+"#"+inFromDate+"#"+inToDate+"#"+uploadedFileName+"$$"+blob);
insertRow(inEmpCode,inFromDate,inToDate,uploadedFileName,blob);
}
//从它的角度看代码
<af:selectOneChoice value="#{AddReviewBean.inEmpCode}"
label="#{bindings.Empcode.label}"
required="#{bindings.Empcode.hints.mandatory}"
shortDesc="#{bindings.Empcode.hints.tooltip}" id="soc1"
valueChangeListener="#{AddReviewBean.onSelectionChange}" autoSubmit="true">
<f:selectItems value="#{bindings.Empcode.items}" id="si1"/>
<f:validator binding="#{bindings.Empcode.validator}"/>
</af:selectOneChoice>
<p xmlns="http://www.w3.org/1999/xhtml">
<af:inputText value="#{AddReviewBean.outDesignation}" readOnly="true" label="Designation" id="txtDesignation"
partialTriggers="soc1"/>
</p>
<p xmlns="http://www.w3.org/1999/xhtml">
<af:inputDate label="From" id="dateTxtFrom" required="true" value="#{AddReviewBean.inFromDate}"/>
</p>
<p xmlns="http://www.w3.org/1999/xhtml">
<af:inputDate label="To" id="dateTxtTo" required="true" value="#{AddReviewBean.inToDate}"/>
</p>
<p xmlns="http://www.w3.org/1999/xhtml">
<af:inputFile label="Upload Review" maximumFiles="1" autoSubmit="true" id="inFileReview"
valueChangeListener="#{AddReviewBean.onFileUploadVCL}" value="#{AddReviewBean.file}"/>
</p>
<p xmlns="http://www.w3.org/1999/xhtml">
<af:button partialSubmit="true" text="Submit" id="btnSubmit"
actionListener="#{AddReviewBean.onSubmit}"/>
</p>
</af:panelFormLayout>
将变量声明为静态变量,它应该可以工作。如果您在pageFlowScope或sessionScope中声明了托管bean(如果您认为它应该在整个用户会话中存活),并将变量设置为私有变量(非静态),那么该变量将保留在那里。您可以将表单代码添加到问题中吗?@MrAdibou done!谢谢,成功了!!。。我将变量声明为public,当它从ValueChangeListener中传出时,它将立即变为null。这绝对是个坏主意,将它设置为static意味着下一个访问此页面的用户将拥有另一个用户上载文件的变量数据!!!