Hi, following samples in community I’ve implemented a controller that loads data into a non persistent entity from a csv file.
In the screen I would like to show the loaded data in a table.
So I’ve tried to bind a temporary datasource to the table but no data are displayed.
Any suggestion ?
Thanks in advance.
Gianluca
Hi Gianluca,
can you share a little bit of your code to get a grasp on where the problem might be? Generally, you can look at Aleksey’s example on github which shows how to create a custom datasource for a table where the data comes from a webservice. You “just” have to adoption of the CurrencyService to a CSV backend.
Do you want to display the data in a non persisted state, or do you want to import the CSV data into the relational database and after that just display the information?
Bye,
Mario
Hi Mario, thanks for your hints.
This is the code that is now fully working.
Hope this could be helpful for someone other with the same problem.
Ciao.
Gianluca
uploadField.addFileUploadSucceedListener(event -> {
FileDescriptor fd = uploadField.getFileDescriptor();
try {
// save file to FileStorage
fileUploadingAPI.putFileIntoStorage(uploadField.getFileId(), fd);
} catch (FileStorageException e) {
throw new RuntimeException("Error saving file to FileStorage", e);
}
// save file descriptor to database
dataSupplier.commit(fd);
showNotification("Uploaded file: " + uploadField.getFileName(), NotificationType.HUMANIZED_HTML);
try {
BufferedReader in = new BufferedReader(new InputStreamReader( new FileDataProvider(fd).provide()));
String line = null;
while ((line = in.readLine()) != null) {
String codCompany = line.substring(0,4); //1 4
String codSubcompany = line.substring(4,8); //5 4
String codPeriodComp = line.substring(8,10); //9 2
String codYearComp = line.substring(11,15); //12 4
String codMember = line.substring(28,32); //29 4
String codTest = line.substring(55,65); //56 10
String desPaccaount = line.substring(68,108); //69 40
String codAmmount = line.substring(108,125); //109 17
String codSection = line.substring(127,128); //128 1
if (codTest.equals("<b></b><b></b>__")) {
System.out.println(line);
// create a LoadContext
TempPayroll tp = metadata.create(TempPayroll.class);
tp.setCodSocieta(codCompany);
tp.setCodSubSocieta(codSubcompany);
tp.setCodPeriodoComp(codPeriodComp);
tp.setCodYearComp(codYearComp);
tp.setCodMember(codMember);
tp.setDesPaccaount(desPaccaount);
tp.setCodAmmount(codAmmount);
tp.setCodSection(codSection);
tempPayrollsDs.addItem(tp);
}
}
} catch (IOException e) {
e.printStackTrace();
}
uploadedData.repaint();
});
uploadField.addFileUploadErrorListener(event ->
showNotification("File upload error", NotificationType.HUMANIZED));
uploadField.addAfterValueClearListener( event -> {
tempPayrollsDs.clear();
uploadedData.repaint(); });
Load data from CSV to table in CUBA platform below is code written for loading student data of name,subject and marks