Search code examples
javajsffile-uploadoracle-adfvaluechangelistener

Value not accessible outside valuechangelistener of Inputfile during fileupload in Oracle ADF


I am creating a form in Oracle ADF in which i am using inputfile to upload a file to db. When i select a file through input file value is recieved in the ValueChangeListener but if i try to access that value outside the valuchangelistener function through public variables or getter , setter functions the value recieved is 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);               
    }

// Code from its view

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

Solution

  • Declare your variables as static and it should work.