json data from code

Stimulsoft Reports.JAVA discussion
Post Reply
jacek@fn-serwis.pl
Posts: 4
Joined: Sun Jan 12, 2025 10:52 am

json data from code

Post 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?
Vadim
Posts: 409
Joined: Tue Apr 23, 2013 11:23 am

Re: json data from code

Post 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();
jacek@fn-serwis.pl
Posts: 4
Joined: Sun Jan 12, 2025 10:52 am

Re: json data from code

Post 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 12780 times
:

After I have:
Zrzut ekranu 2025-02-10 082206.jpg
Zrzut ekranu 2025-02-10 082206.jpg (31.46 KiB) Viewed 12780 times
I think the problem is that I don't do 'select data' when I add data in the code
jacek@fn-serwis.pl
Posts: 4
Joined: Sun Jan 12, 2025 10:52 am

Re: json data from code

Post by jacek@fn-serwis.pl »

I saw in debuger I have no info in dataSource about my data. How add (register) data into dataSource
jacek@fn-serwis.pl
Posts: 4
Joined: Sun Jan 12, 2025 10:52 am

Re: json data from code

Post 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
Lech Kulikowski
Posts: 7299
Joined: Tue Mar 20, 2018 5:34 am

Re: json data from code

Post by Lech Kulikowski »

Hello,

Thank you for the information.
Post Reply