json data from code
-
- Posts: 4
- Joined: Sun Jan 12, 2025 10:52 am
json data from code
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?
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
Hello
You should setup Database name
is not necessary
You should setup Database name
Code: Select all
new StiJsonDatabase(String name, String pathData)
is not necessary
Code: Select all
report.getDictionary().connect();
-
- Posts: 4
- Joined: Sun Jan 12, 2025 10:52 am
Re: json data from code
It still doesn't work.
In designer when I manually add data I get dialog window 'select data': :
After I have:
I think the problem is that I don't do 'select data' when I add data in the code
In designer when I manually add data I get dialog window 'select data': :
After I have:
I think the problem is that I don't do 'select data' when I add data in the code
-
- Posts: 4
- Joined: Sun Jan 12, 2025 10:52 am
Re: json data from code
I saw in debuger I have no info in dataSource about my data. How add (register) data into dataSource
-
- Posts: 4
- Joined: Sun Jan 12, 2025 10:52 am
Re: json data from code
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
StiJsonDatabase db = (StiJsonDatabase)report.getDictionary().getDatabases().get("data-test");
db.setPathData("https://abc.pl:1091/api/printdata/id/5");
Thank's
-
- Posts: 7299
- Joined: Tue Mar 20, 2018 5:34 am
Re: json data from code
Hello,
Thank you for the information.
Thank you for the information.