Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Difference between instruction params["name_param"].value=some_value and reportContext.setPa
bognekadje
Hi Birt community,
I want to know what is the difference between instruction:
-params["name_param"].value=some_value and
-reportContext.setParameterValue("nom_param",some_value)
in a script such as ReportDesign.BeforeFactory
Can you explain me what is variable reportContext and how can we retrieve it using BIRT API.
Thanks for reply.
Eric.
Find more posts tagged with
Comments
JasonW
Eric,
reportContext is a global BIRT js object that has several methods that are available while in BIRT script. What are you trying to do in the API?
Jason
bognekadje
Thanks for reply Jason,<br />
I have report which BeforeFactory script. This script set some parameters values.<br />
What i want to do is display the new value in my application to be sure that values<br />
are set. But after run the report and generate the rptdocument, instruction <br />
IrunTask.getParameterValues() does not show me parameters set in the script.<br />
But after create the RenderTask and remake instruction IrunTask.getParameterValues()<br />
variables set in the script are show, but which null value.<br />
Here is the code i use:<br />
<br />
method which create .rptdocument file<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>public static void createRptDoc(ReportDetails rd, ServletContext sc){
IReportEngine re = getReportEngine(sc);
IReportRunnable reportRun = null;
viewRDParamValue(rd);
try {
reportRun = re.openReportDesign(rd.getPath());
} catch (EngineException e) {
e.printStackTrace();
}
IRunTask runTask = re.createRunTask(reportRun); //ReportingConfig.class.getClassLoader()
runTask.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, Thread.currentThread().getContextClassLoader());
//viewTaskParamValue(runTask);
String[] s = rd.getName().split("\\.");
String docPath = getRptdocument_folder(sc)+File.separator+s[0]+".rptdocument";
setValueRunTaskReport(runTask, rd);
boolean valid = runTask.validateParameters();
if(valid){
System.out.println("Validation succeed!");
}else{
System.out.println("Validation failed!");
}
viewTaskParamValue(runTask);
try {
runTask.run(docPath);
} catch (EngineException e) {
e.printStackTrace();
}
viewTaskParamValue(runTask);
}
</pre>
<br />
method which create html output<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>public static int createHtmlOutput(ReportDetails rd, ServletContext sc){
IReportEngine re = getReportEngine(sc);
IReportDocument rptdoc;
String[] s = rd.getName().split("\\.");
String docPath = getRptdocument_folder(sc)+File.separator+s[0]+".rptdocument";
String outputPath = getRptoutput_folder(sc)+File.separator+s[0];
int nbPage = 0;
try {
rptdoc = re.openReportDocument(docPath);
HTMLRenderOption htmlOption = new HTMLRenderOption();
htmlOption.setOutputFormat(IRenderOption.OUTPUT_FORMAT_HTML);
htmlOption.setEmbeddable(false);
htmlOption.setImageDirectory(getRptimage_folder(sc));
htmlOption.setSupportedImageFormats("PNG;GIF;JPG;BMP");
htmlOption.setOutputFileName(outputPath+".html");
htmlOption.setHtmlPagination(true);
htmlOption.setMasterPageContent(true);
IRenderTask renderTask = reportEngine.createRenderTask(rptdoc);
viewTaskParamValue(renderTask);
renderTask.setRenderOption(htmlOption);
nbPage = (int) renderTask.getTotalPage();
//System.out.println("Nombre de page = "+nbPage);
for(int i = 1; i <= nbPage; i++){
htmlOption.setOutputFileName(outputPath+i+".html");
renderTask.setRenderOption(htmlOption);
renderTask.setPageNumber(i);
renderTask.render();
}
} catch (EngineException e) {
e.printStackTrace();
}
return nbPage;
}
</pre>
<br />
method to display parameters and theirs values<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>private static void viewTaskParamValue(IEngineTask task){
HashMap h = task.getParameterValues();
List l = new ArrayList<Object>(h.keySet());
String s;
System.out.println("VIEW TASK PARAMETERS VALUE");
for(int i = 0; i < l.size(); i++){
Object o = h.get(l.get(i));
if(o == null){
s = "null";
}else{
if(o instanceof Object[]){
String q = new String();
for(int j = 0; j < ((Object[])o).length; j++){
q = q+"["+((Object[])o)[j].toString()+"]";
}
s = q;
}else{
s = o.toString();
}
}
System.out.println("Name = "+l.get(i).toString()+" - Value = "+s);
}
}
</pre>
<br />
<br />
BeforeFactory script which modify some parameters<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage (Packages.com.lemoinetechnologies.pulse.reports.functions);
importPackage(Packages.java.lang);
// PulseMinDate / PulseMaxDate
var minDate = params["PulseMinDate"].value;
var maxDate = params["PulseMaxDate"].value;
var minMaxDates = DateSelection.getMinMaxDates (params["PulseDateRange"].value,
minDate, maxDate);
System.out.println("BeforeFactory ...");
params["PulseMinDate"].value = minMaxDates [0];
params["PulseMaxDate"].value = minMaxDates [1];
System.out.println("PulseMinDate ="+params["PulseMinDate"].value);
System.out.println("PulseMaxDate ="+params["PulseMaxDate"].value);
//params["PulseMinDate"].value = new Date();
//params["PulseMaxDate"].value = new Date();
// Check analysis
analysisMessage = reportContext.getMessage(CheckAnalysis.check (minMaxDates[0], minMaxDates[1]),
reportContext.getLocale());
params["PulseInfoMessage"].value = CheckAnalysis.updateMessage (params["PulseInfoMessage"].value,
analysisMessage);
System.out.println("PulseInfoMessage ="+params["PulseInfoMessage"].value);
// Orientation
var orientationParam = params["orientation"].value;
if (orientationParam != null) {
var pages = reportContext.getDesignHandle().getModuleHandle().getAllPages();
for(var i = 0; i < pages.size(); i++) {
var page = pages.get(i);
page.setProperty("orientation", orientationParam);
}
}
// Current date
if (params["currentdate"].value == null) {
params["currentdate"].value = new Date();
}
System.out.println("currentdate ="+params["currentdate"].value);
</pre>
<br />
Thanks for your help<br />
<br />
Eric.