Passing Customized Variables to User Data Source at Runtime
You can pass customized variables to a user data source (UDS) at runtime, by implementing the jet.datasource.JRUserServerInfoDataSource interface and adding customized variables in the session or URL. This topic describes how to pass customized variables to UDS.
- Implement the jet.datasource.JRUserServerInfoDataSource interface so that your UDS can receive customized variables.
- Read customized variables in UDS. Server collects customized variables from the session or URL and stores them in a java.util.Properties in the jet.server.api.ServerInfo interface. You can then get the java.util.Properties to obtain the customized variables, through ServerInfo.getTaskProperties().
Properties props = getServerInfo().getTaskProperties();
String var1 = props.getProperty("UDP$Var1");
String var2 = props.getProperty("UDP$Var2"); - You can use the following three ways to set customized variables to UDS, with the priority from highest to lowest:
- Set customized variables using the Report session variable feature. Use a java.util.Properties to collect all customized variables and set the java.util.Properties by HttpSession.setAttribute to the HttpSession with the key JReport_running_parameter. See the following example:
Properties ssnVars = new Properties();
ssnVars.setProperty("Var1", "a");
ssnVars.setProperty("Var2", "b");
HttpSession httpsession = request.getSession();
httpsession.setAttribute("JReport_running_parameter", ssnVars); - Set customized variables in the HttpSession, by setting attributes that start with UDP$.
HttpSession httpsession = request.getSession();
httpsession.setAttribute("UDP$Var1", "a");
httpsession.setAttribute("UDP$Var2", "b"); - Set customized variables in the URL of running a report, by setting parameters that start with UDP$.
http://localhost:8888/jinfonet/runReport.jsp?jrs.report=%2freport1.wls&jrs.catalog=%2fSampleReports.cat&jrs.result_type=8&UDP$Var1=a&UDP$Var2=b
- Set customized variables using the Report session variable feature. Use a java.util.Properties to collect all customized variables and set the java.util.Properties by HttpSession.setAttribute to the HttpSession with the key JReport_running_parameter. See the following example: