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);
}
}
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.