Constructor<?> constructor = defaultUploadedFileClass.getDeclaredConstructor(FileItem.class);
Object defaultUploadedFile = constructor.newInstance(fileItem);
// If the PrimeFaces FileUpload component is in "simple" mode, then simply set the submitted
// value of the component to the DefaultUploadedFile instance.
PrimeFacesFileUpload primeFacesFileUpload = new PrimeFacesFileUpload((UIInput) uiComponent);
if (primeFacesFileUpload.getMode().equals(PrimeFacesFileUpload.MODE_SIMPLE)) {
logger.debug("Setting submittedValue=[{0}]", submittedValue);
primeFacesFileUpload.setSubmittedValue(defaultUploadedFile);
}
// Otherwise,
else {
logger.debug("Queuing FileUploadEvent for submittedValue=[{0}]", submittedValue);
// Reflectively create an instance of the PrimeFaces FileUploadEvent class.
Class<?> uploadedFileClass = Class.forName(FQCN_UPLOADED_FILE);
Class<?> fileUploadEventClass = Class.forName(FQCN_FILE_UPLOAD_EVENT);
constructor = fileUploadEventClass.getConstructor(UIComponent.class, uploadedFileClass);
FacesEvent fileUploadEvent = (FacesEvent) constructor.newInstance(uiComponent,
defaultUploadedFile);
// Queue the event.
primeFacesFileUpload.queueEvent(fileUploadEvent);
}
}
}
}
}