0

I need to add the ability to upload an XLSX file in an existing project. I act according to the instructions http://www.awasthiashish.com/2017/01/import-data-from-xls-and-xlsx-excel-to.html. The question is that when I select an XLSX file, nothing happens. I put the logs inside the uploadFileVCE method, when I upload a file it doesn't output anything, as if it doesn't even enter the method. Help, can anyone come across.

ADF version: Studio Edition Version 12.2.1.0.0

Here is my jsff file:

<af:inputFile label="Upload file" id="if1"
valueChangeListener="#{pageFlowScope.Class1Bean.uploadFileVCE}"
autoSubmit="true" 
labelStyle="font-weight:bold;color:navy;"/>

here is my Bean class:

 public void uploadFileVCE(ValueChangeEvent valueChangeEvent) {
        log.warn("FIRST");
            UploadedFile file = (UploadedFile) valueChangeEvent.getNewValue();
            log.warn("SECOND");
            try {
                //Check if file is XLSX
                log.warn("THIRD");
                if (file.getContentType().equalsIgnoreCase("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") ||
                    file.getContentType().equalsIgnoreCase("application/xlsx")) {
                    log.warn("FOURTH");
                    readNProcessExcelx(file.getInputStream()); //for xlsx

                }
                //Check if file is XLS
                else if (file.getContentType().equalsIgnoreCase("application/vnd.ms-excel")) {

                    if (file.getFilename().toUpperCase().endsWith(".XLS")) {
                       // readNProcessExcel(file.getInputStream()); //for xls
                    }

                } else {
                    FacesMessage msg = new FacesMessage("File format not supported.-- Upload XLS or XLSX file");
                    msg.setSeverity(FacesMessage.SEVERITY_WARN);
                    FacesContext.getCurrentInstance().addMessage(null, msg);
                }
                AdfFacesContext.getCurrentInstance().addPartialTarget(empTable);

            } catch (Exception e) {
                log.warn(e);
            }
        }
Yevgeniy
  • 42
  • 5
  • Does this answer your question? [How to upload file using JSF 2.2 ? Where is the saved File?](https://stackoverflow.com/questions/27677397/how-to-upload-file-using-jsf-2-2-hinputfile-where-is-the-saved-file) – XtremeBaumer Jan 16 '23 at 13:43
  • @XtremeBaumer I don't think this article answers my question, thanks! – Yevgeniy Jan 16 '23 at 13:50
  • Try to debug the method by setting a breakpoint to the first line in the method. If you don't see any of your messages in the log, check that the log level is set to 'WARNING' at least. Or, just for a test, use a `System.out.println` for the message and see if you see those in the logs. – Timo Hahn Jan 17 '23 at 12:10
  • Does this answer your question? [ADF af:inputFile does not trigger ValueChangeEvent with valueChangeListener](https://stackoverflow.com/questions/36032476/adf-afinputfile-does-not-trigger-valuechangeevent-with-valuechangelistener) – Cedric Jan 18 '23 at 05:38
  • I resolve this problem. I have – Yevgeniy Jan 18 '23 at 08:51

1 Answers1

0

The solution to this problem is to add a parameter usesUpload="true". I have this form <af:form was set in another .jsff file, so I added the usesUpload="true" parameter to the file where the form was located.

Yevgeniy
  • 42
  • 5