[英]Value not accessible outside valuechangelistener of Inputfile during fileupload in Oracle ADF
我正在 Oracle ADF 中創建一個表單,其中我使用 inputfile 將文件上傳到 db。 當我通過在 ValueChangeListener 中接收到的輸入文件值選擇文件時,但如果我嘗試通過公共變量或 getter 訪問該值在 valuechangelistener 函數之外,setter 函數則接收到的值為空。
// 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(如果您認為它應該在整個用戶會話中存活)並將變量設為私有(非靜態),則該變量將保留在那里。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.