[Solved] How to populate table/grid

1
0
-1

Hi,

As a newby in using Bonita, I am getting a little confused here when trying to populate a grid in version 6.2

I have the following groovy code the get some values from an Excel file:

  1. import java.io.File;
  2. import java.util.Date;
  3. import jxl.*;
  4.  
  5. List excellist = new ArrayList();
  6.  
  7. excellist.clear();
  8. //read excel file
  9. Workbook wb = Workbook.getWorkbook(new File('D:/someexcelfile.xls'));
  10. Sheet sheet = wb.getSheet(0);
  11.  
  12. for (int i=1; i<sheet.getRows();i++)
  13. {
  14. for (int j=0; j<sheet.getColumns(); j++)
  15. {
  16. p=sheet.getCell(j,i).getContents();
  17. excellist.add(p);
  18.  
  19. }
  20. }
  21.  
  22. wb.close();
  23. return excellist;

When evaluating the code gives the desired list van string values. However I see no means to link it to the table in order to populate it. Each time I get an page form error of which I cannot tell what the error exactly is? Any help is appreciated.

Best regards Frank

2 answers

1
0
-1
This one is the BEST answer!

In order to display your data in a list or a grid, you should use a list of lists, that would be structured in two dimensions, something like this (not tested):

  1. import java.io.File;
  2. import java.util.Date;
  3. import jxl.*;
  4. //create list of lists
  5. List<List<String>> resultTable = new ArrayList<List<String>>();
  6.  
  7. //read excel file
  8. Workbook wb = Workbook.getWorkbook(new File('D:/someexcelfile.xls'));
  9. Sheet sheet = wb.getSheet(0);
  10.  
  11. for (int i=1; i<sheet.getRows();i++)
  12. {
  13. List excellist = new ArrayList();
  14. for (int j=0; j<sheet.getColumns(); j++)
  15. {
  16. p=sheet.getCell(j,i).getContents();
  17. excellist.add(p);
  18. }
  19. resultTable.add(excellist);
  20. }
  21.  
  22. wb.close();
  23. return resultTable;

Comments

Submitted by frank.vtour on Tue, 04/29/2014 - 07:59

OK, a 2 dimensional array makes sense in repesct to the table to fill. I adjusted the script and now I get, when evaluating, the values of the rows and columns for the Excel sheet. However when showing in the browser it still reports "Error while getting the form page list". Why?

Submitted by haris.subasic on Tue, 04/29/2014 - 09:23

Great, you are moving forward :) Could you get us extract from the log, corresponding to that error, please?

Submitted by frank.vtour on Tue, 04/29/2014 - 09:42

Can point out which log you're referring too?

Submitted by haris.subasic on Tue, 04/29/2014 - 09:43

I assume that you are testing in the Studio, so it would be Engine log, accessible through Help menu in the Studio

Submitted by frank.vtour on Tue, 04/29/2014 - 09:51

Ahh, found some valueable resource here, was looking for that. Two errors are reported:

  1. Script1.groovy: 11: unable to resolve class Workbook
  2. @ line 11, column 10.
  3. Workbook wb = Workbook.getWorkbook(new File('someexcel.xls'));
  4. Script1.groovy: 12: unable to resolve class Sheet
  5. @ line 12, column 7.
  6. Sheet sheet = wb.getSheet(0);

Apparently the jxl-2.6jar is not referenced automatically. Strange as this is working when evaluting the script directly.

Submitted by haris.subasic on Tue, 04/29/2014 - 10:17

Can you try to add this jar as a dependency to your process, using process configuration?

Submitted by frank.vtour on Tue, 04/29/2014 - 11:25

When searching for adding dependecies I found

Dependencies are primarily managed through the Development menu. This makes the external module available for all processes. You can also import a dependency when you configure a process, but in this case, it is only available for the process you are configuring.

The first part I already did, added the jxl.jar globally. In order to import the .jar excusievely to a process I can not find the entry where to do so. Is this done in the groovy script? When deselecting the automatic dependencies resolution, I still can not add the jxl.jar, only the table object name is listed here for selection

Submitted by haris.subasic on Tue, 04/29/2014 - 11:29

I was rather refering to this section.

Submitted by frank.vtour on Tue, 04/29/2014 - 11:49

Finally it's working!! Still the process dependencies window of the configuration is confusing as you can add the dependency to the 'groovy scripts' section (by selecting deselecting the process dependencies item in the treeview), as I thought we're talking scripts now. But apparently the dependency must added to the 'others' section otherwhise the added dependency is not saved and when calling configuration again it is disappeared. Thanks for your support and patience.

Submitted by haris.subasic on Tue, 04/29/2014 - 14:39

Great news, thank you for your feedback and happy to hear that it works. This will definitely help others, as well. Good luck and have fun with Bonita BPM :)

1
0
-1

Hello,

You should have a look at our Trello Example: http://community.bonitasoft.com/project/trello-application-example-inclu...

There is a step where data are displayed in a table, and downloadable .csv is generated with the file widget. Tell me if it helps !

Comments

Submitted by frank.vtour on Mon, 04/28/2014 - 11:12

Hello ttoine,

Thanks for pointing out the example. I'm afraid using connecters etc. is a bridge too far this moment. Just want to understand why a (simple) return list (refer to the groovy script) is not accepted as data input for the table. I see you using all kind of JSON stuff to manage this. Hopefully there is some simple straightforward example available which make me understand the data requirements of a grid. By the way I also tried the same script on a listbox, again with the same negative result. Finally I'm not a JAVA guru just considering myself as entry level novice.

best regards, Frank

Notifications