【问题标题】:Value not accessible outside valuechangelistener of Inputfile during fileupload in Oracle ADF在 Oracle ADF 中的文件上传期间,在 Inputfile 的 valuechangelistener 之外无法访问值
【发布时间】:2018-04-08 16:38:27
【问题描述】:

我正在 Oracle ADF 中创建一个表单,在该表单中我使用 inputfile 将文件上传到 db。当我通过在 ValueChangeListener 中收到的输入文件值选择文件时,但如果我尝试通过公共变量或 getter 在 valuchangelistener 函数之外访问该值,则 setter 函数收到的值为 null。

// 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>

【问题讨论】:

  • 您可以将表单代码添加到您的问题中吗?
  • @MrAdibou 完成!

标签: java jsf file-upload oracle-adf valuechangelistener


【解决方案1】:

将你的变量声明为静态的,它应该可以工作。

【讨论】:

  • 谢谢它的工作!!..我将变量声明为公共变量,它从 ValueChangeListener 中出来后立即变为空。
  • 这绝对是个坏主意,将其设置为静态意味着下一个访问此页面的用户将拥有另一个用户上传文件的可变数据!!!
【解决方案2】:

如果您在 pageFlowScope 或 sessionScope 中声明托管 bean(如果您认为它应该在整个用户会话中存活)并将变量设为私有(非静态),则该变量将保留在那里。

【讨论】:

    猜你喜欢
    • 2014-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-15
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    • 1970-01-01
    相关资源
    最近更新 更多