java example exception in viewer.jsp

Stimulsoft Reports.JAVA discussion
xiaohaoxifei
Posts: 34
Joined: Mon Sep 18, 2017 6:07 am

Re: java example exception in viewer.jsp

Post by xiaohaoxifei »

Thanks for your replay.

I've got two questions here:
1, Do we have some internationalization solution with the stimulsoft report?
2, For the designer page, is there an option to set for auto-resizing the whole page?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: java example exception in viewer.jsp

Post by HighAley »

Hello.

1. Yes, you could use the Globalization Strings feature to add multi-language support.
https://www.stimulsoft.com/en/documenta ... editor.htm

2. No, you should change the position for all components of the report.

Thank you.
xiaohaoxifei
Posts: 34
Joined: Mon Sep 18, 2017 6:07 am

Re: java example exception in viewer.jsp

Post by xiaohaoxifei »

I've created a .mrt template which has a JSON data source, a normal formatted JSON file and everything is OK. And I tried to replace the json data source value at the running time just like replacing the SQL statement. I used the following code but new JSON data is not displayed OK in the viewer page.

Code: Select all

if (!queryStr.isEmpty()) {
                            StiJsonDatabase stiJsonDatabase = ((StiJsonDatabase) stiDatabaseCollection.get(0));
                            stiJsonDatabase.setEmbeddedData(queryStr);
                            stiJsonDatabase.setJsonData(queryStr);

                        }
The "queryStr" is a JSON String. And I tried to remove the former data source and add a new created data source with the "queryStr", still not work.

Please help, thanks a lot. If possible, show some code. Huge thanks.
Vadim
Posts: 362
Joined: Tue Apr 23, 2013 11:23 am

Re: java example exception in viewer.jsp

Post by Vadim »

Hello.
Please set path to null

Code: Select all

 
if (!queryStr.isEmpty()) {
                            StiJsonDatabase stiJsonDatabase = ((StiJsonDatabase) stiDatabaseCollection.get(0));
                            stiJsonDatabase.setPathData(null);
                            stiJsonDatabase.setEmbeddedData(queryStr);
                        }
xiaohaoxifei
Posts: 34
Joined: Mon Sep 18, 2017 6:07 am

Re: java example exception in viewer.jsp

Post by xiaohaoxifei »

I've successfully replaced the json data of the data source in the viewer page, but things are little different in the designer page.

Code: Select all

StiWebDesigerHandler handler = new StiWebDesigerHandler() {
            //Occurred on loading webdesinger. Must return edited StiReport
            public StiReport getEditedReport(HttpServletRequest request) {
                try {
//                StiReport report = StiSerializeManager.deserializeReport(new FileInputStream(reportPath));
                    StiReport report = reportPath == "" ? StiReport.newInstance() : StiSerializeManager.deserializeReport(new FileInputStream(reportPath));
                    if (reportName == "") {
                        report.setReportName( request.getParameter("report").replace(".mrt",""));
                        RequestContext requestContext = new RequestContext(request, response);
						//json format data
                        String qryStr = JsonUtils.objectToJson(request.getAttribute("reportJsonReturn"), requestContext.getMessage("date_format"));
                        StiJsonDatabase jsonDatabase = new StiJsonDatabase("json");
						//set json data source
                        jsonDatabase.setEmbeddedData(qryStr);
                        report.getDictionary().getDatabases().add(jsonDatabase);
                    } 
                    return report;
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }

            //Occurred on opening StiReport. Method intended for populate report data.
            public void onOpenReportTemplate(StiReport report, HttpServletRequest request) {
            }

            //Occurred on new StiReport. Method intended for populate report data.
            public void onNewReportTemplate(StiReport report, HttpServletRequest request) {
            }

            //Occurred on save StiReport. Method must implement saving StiReport
            public void onSaveReportTemplate(StiReport report, StiRequestParams requestParams, HttpServletRequest request) {
                try {
                    FileOutputStream fos = new FileOutputStream(savePath + requestParams.designer.fileName);
                    if (requestParams.designer.password != null) {
                        StiSerializeManager.serializeReport(report, fos, requestParams.designer.password);
                    } else {
                        StiSerializeManager.serializeReport(report, fos, true);
                    }
                    fos.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
The data source seems to be added, but there are no data in it.

I found out that the dataSources is null and databases has value. So, after the database is added, any action should be proceeded for loading the dataSources?
Attachments
no_data.png
no_data.png (14.56 KiB) Viewed 5445 times
Vadim
Posts: 362
Joined: Tue Apr 23, 2013 11:23 am

Re: java example exception in viewer.jsp

Post by Vadim »

Hello.
You should parse database & add fileds, like in example

Code: Select all

public StiReport getEditedReport(HttpServletRequest request) {
	            try {
	                StiReport report = StiReport.newInstance();
	                StiJsonDatabase jsonDatabase = new StiJsonDatabase("json");
	                String jsonData = StiIOUtil.toString(new FileInputStream("c:/2.json"));
	                jsonDatabase.setEmbeddedData(jsonData);
	                report.getDictionary().getDatabases().add(jsonDatabase);
	                DataSet dataSet = StiJsonToDataSetConverterV2.getDataSet(((StiJsonDatabase) jsonDatabase).getJSONObject());
                            for (DataTable table : dataSet.getTables()) {
                                StiJsonSource source = new StiJsonSource("json." + table.getName(), "json." + table.getName());
                                source.setDictionary(report.getDictionary());
        						report.getDictionary().getDataSources().add(source);
        						source.setColumns(new StiDataColumnsCollection());
        						for (StiDataColumn col : table.getColumns()){
        							source.getColumns().add(col);
        						}                                
                            }
	                return report;
	            } catch (Exception e) {
	                e.printStackTrace();
	            }
	            return null;
	        }
xiaohaoxifei
Posts: 34
Joined: Mon Sep 18, 2017 6:07 am

Re: java example exception in viewer.jsp

Post by xiaohaoxifei »

Thank you for your quick reply so much.

I've got the dataSources now, but the data list is different from loading the Json file by creating data source manually.

By which I mean, can we show the data-list selection page as soon as the designer page is loaded?
Attachments
data_select.png
data_select.png (45.24 KiB) Viewed 5430 times
Vadim
Posts: 362
Joined: Tue Apr 23, 2013 11:23 am

Re: java example exception in viewer.jsp

Post by Vadim »

Hello.
You can add only StiJsonDatabase in code, than user right-click "New Data Source" on Dictionary and select databse in "Report Connectios" - data-list selection page will appear.
xiaohaoxifei
Posts: 34
Joined: Mon Sep 18, 2017 6:07 am

Re: java example exception in viewer.jsp

Post by xiaohaoxifei »

Vadim wrote:Hello.
You can add only StiJsonDatabase in code, than user right-click "New Data Source" on Dictionary and select databse in "Report Connectios" - data-list selection page will appear.
:lol: You're my hero.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: java example exception in viewer.jsp

Post by Alex K. »

Hello

We are always glad to help you!
Please let us know if you need any additional help.

Thank you.
Post Reply