Page 1 of 1

json data from code

Posted: Fri Feb 07, 2025 11:15 am
by jacek@fn-serwis.pl
Hello

I have prepared a report with data from Api in json format. It works. Now I would like to feed the report with this data, but I want to provide the path from the code.
I tried the following:

String reportPath = context.getRealPath("/reports/report.mrt");
StiReport report = StiSerializeManager.deserializeReport(new File(reportPath));

report.getDictionary().clear();
StiJsonDatabase db = new StiJsonDatabase();

db.setPathData("https://abc.pl:1091/api/printdata");

report.getDictionary().getDatabases().add(db);
report.getDictionary().connect();

System.out.println(report.getDictionary());

report.render();
StiWebViewerOptions options = new StiWebViewerOptions();
options.getToolbar().setZoom(97);
options.getToolbar().setViewMode(StiWebViewMode.SinglePage);

return new ReportViewerOptions(report, options);

It doesn't work.
what's wrong?

Re: json data from code

Posted: Fri Feb 07, 2025 2:00 pm
by Vadim
Hello

You should setup Database name

Code: Select all

new StiJsonDatabase(String name, String pathData) 

is not necessary

Code: Select all

report.getDictionary().connect();

Re: json data from code

Posted: Mon Feb 10, 2025 7:37 am
by jacek@fn-serwis.pl
It still doesn't work.

In designer when I manually add data I get dialog window 'select data':
Zrzut ekranu 2025-02-10 081709.jpg
Zrzut ekranu 2025-02-10 081709.jpg (40.45 KiB) Viewed 16718 times
:

After I have:
Zrzut ekranu 2025-02-10 082206.jpg
Zrzut ekranu 2025-02-10 082206.jpg (31.46 KiB) Viewed 16718 times
I think the problem is that I don't do 'select data' when I add data in the code

Re: json data from code

Posted: Mon Feb 10, 2025 9:05 am
by jacek@fn-serwis.pl
I saw in debuger I have no info in dataSource about my data. How add (register) data into dataSource

Re: json data from code

Posted: Mon Feb 10, 2025 11:19 am
by jacek@fn-serwis.pl
I solved the problem. I replaced path data in databese object:

StiJsonDatabase db = (StiJsonDatabase)report.getDictionary().getDatabases().get("data-test");
db.setPathData("https://abc.pl:1091/api/printdata/id/5");

Thank's

Re: json data from code

Posted: Mon Feb 10, 2025 3:54 pm
by Lech Kulikowski
Hello,

Thank you for the information.