Integrating JavaScript APIs into your environment
With the JavaScript APIs provided by JReport, you can successfully embed page reports, web reports and dashboards into your own application and then perform actions outside the report template without using Page Report Studio, Web Report Studio, or JDashboard.
The implemented JavaScript APIs in an external application can be applied to perform the following actions on the embedded reports and dashboards:
The JavaScript APIs that JReport provides is a single JavaScript file jreportapi.js. It is created in the <JReportServer_install_root>\public_html\webos\jsvm\lib
folder by the JavaScript making tool. There are two ways to use the JavaScript APIs in customer's application.
<JReportServer_install_root>\public_html\webos\jsvm\lib
to a folder C:\API
in the customer's application. <script id="j$vm" type="text/javascript" src="C:\API\jreportapi.js"></script>
Assume that JReport Server is running on 192.168.0.1:8888. Then you can load jreportapi.js by setting the URL http://192.168.0.1:8888/webos/jsvm/lib/jreportapi.js
in the customer's html page as follows:
<script id="j$vm" type="text/javascript" src="http://192.168.0.1:8888/webos/jsvm/lib/jreportapi.js"></script>
JReport Server provides two demos in the <JReportServer_install_root>\public_html\webos\app\demo
folder:
To run the demos:
http://localhost:8888/webos/app/demo/jreportapi-demo-rpt.html
http://localhost:8888/webos/app/demo/jreportapi-demo-dsb.html
For the dashboard demo, two dashboards are opened and their names are shown above the dashboard body. You can click the names to switch between the two dashboards.
As for the detailed JavaScript APIs and methods of each API that JReport provides, refer to the API documentation in the <JReportServerinstall_root>\help\javascriptapi
folder.
When the reports or dashboards embedded in an application contain parameters, you need to specify parameters when running them. See the following example for a page report:
|
After the reports or dashboards are opened, you can take the following API functions to get and change their parameter values.
@param parameterInfo Array.
[
{
pname: String. The parameter name.
pvalue: Array. The parameter value. For most parameter types pvalue has only one element, but a multi-value parameter may have several elements.
ownerID: Array. The report ID or library component ID which uses the current parameter. ownerID is not necessary for reports, but must be provided for dashboards.
}
...
]
You can find the detailed usage in the two files Dashboard.js and ReportSet.js in the <server_install_root>\public_html\webos\jsvm\src\com\jinfonet\api
directory.
When the reports or dashboards are embedded in a single sign on environment, you should specify the authorized user in your code. The following shows how to specify a user for single sign on as compared to normal login.
For common login, user name and password are set as:
user: "admin",
pass: "admin",
See the following example:
var server = {
url: "http://localhost:8888/jinfonet/tryView.jsp",
user: "admin",
pass: "admin",
jrd_prefer:{
// For page report
pagestudio:{
feature_UserInfoBar:false,
feature_ToolBar: false,
feature_Toolbox: false,
feature_DSOTree: false,
feature_TOCTree: false,
feature_PopupMenu: false,
feature_ADHOC: false
},
// For web report
wrptstudio:{
viewMode:{
hasToolbar: false,
hasSideArea: false
}
}
},
jrd_studio_mode: "view",
"jrs.param_page": true
},
For single sign on, use authorized_user:"user_name" to specify the authorized user as follows:
var server = {
url: "http://localhost:8888/jinfonet/tryView.jsp",
authorized_user:"admin",
jrd_prefer:{
// For page report
pagestudio:{
feature_UserInfoBar:false,
feature_ToolBar: false,
feature_Toolbox: false,
feature_DSOTree: false,
feature_TOCTree: false,
feature_PopupMenu: false,
feature_ADHOC: false
},
// For web report
wrptstudio:{
viewMode:{
hasToolbar: false,
hasSideArea: false
}
}
},
jrd_studio_mode: "view",
"jrs.param_page": true
},