Page 4 of 7

Re: java example exception in viewer.jsp

Posted: Mon Oct 23, 2017 5:49 am
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?

Re: java example exception in viewer.jsp

Posted: Mon Oct 23, 2017 7:30 am
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.

Re: java example exception in viewer.jsp

Posted: Tue Oct 24, 2017 8:16 am
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.

Re: java example exception in viewer.jsp

Posted: Wed Oct 25, 2017 9:47 am
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);
                        }

Re: java example exception in viewer.jsp

Posted: Thu Oct 26, 2017 9:47 am
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?

Re: java example exception in viewer.jsp

Posted: Fri Oct 27, 2017 6:10 am
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;
	        }

Re: java example exception in viewer.jsp

Posted: Fri Oct 27, 2017 6:55 am
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?

Re: java example exception in viewer.jsp

Posted: Fri Oct 27, 2017 7:09 am
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.

Re: java example exception in viewer.jsp

Posted: Fri Oct 27, 2017 7:45 am
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.

Re: java example exception in viewer.jsp

Posted: Mon Oct 30, 2017 6:21 am
by Alex K.
Hello

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

Thank you.