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)
how to retrieve report parameters at runtime
omittag
Hi all,
In some java event handler I need to loop through a collection of all report parameters without knowing their names.
Does anybody know how to achieve this, please ?
Thanks in advance
Find more posts tagged with
Comments
mwilliams
Hi omittag,
What are you trying to do with this information?
johnw
This is some pretty serious scripting involved. You would use what is called a Parameter Extraction task on the current reports ReportRunnable class. The method for iterating through the parameters in an event handler is demonstrated here:
http://birtworld.blogspot.com/2008/04/data-driven-reports.html
John
omittag
I have a database column which contains HTML and before displaying the content as formatted text in text element, I want to perform a replacement of all occurences of Strings like #parametername# with the parameter value of parametername. This should work generic for all reports. I finally got it working (thanks to Raghu Raman !):
package de.actuate.ps;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import org.eclipse.birt.report.engine.api.script.IReportContext;
import org.eclipse.birt.report.engine.api.script.ScriptException;
import org.eclipse.birt.report.engine.api.script.element.ITextItem;
import org.eclipse.birt.report.engine.api.script.eventadapter.TextItemEventAdapter;
import org.eclipse.birt.report.engine.api.script.instance.ITextItemInstance;
import org.eclipse.birt.report.model.api.ParameterHandle;
import org.eclipse.birt.report.model.api.ScalarParameterHandle;
public class TI_Adapter extends TextItemEventAdapter {
PrintWriter pw;
private void log(String msg){
FileWriter fw = null;
pw = null;
try {
fw = new FileWriter("c:\\dfs_log.txt",true);
pw = new PrintWriter(fw);
pw.println(msg);
pw.close();
fw.close();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onCreate(ITextItemInstance text, IReportContext reportContext) {
// TODO Auto-generated method stub
//super.onCreate(text, reportContext);
String content = null;
Object obj;
try {
content = text.getRowData().getColumnValue("htmlDescription").toString();
ScalarParameterHandle sh;
List<ParameterHandle> parameters = reportContext.getDesignHandle().getAllParameters();
log("");
log("SIZE= " + parameters.size());
log(parameters.get(0).getClass().getName());
Iterator iter = parameters.iterator();
while(iter.hasNext()){
log("
");
obj = iter.next();
log(">>> "+obj.getClass().getName());
sh = (ScalarParameterHandle) obj;
String pName = sh.getName();
Object pValue = reportContext.getParameterValue(pName);
log("pName="+pName);
log("sh.getDefaultValue="+sh.getDefaultValue());
log("pValue="+pValue);
log(content);
if(pValue instanceof String) content = content.replaceAll("#"+pName+"#", (String) pValue);
}
} catch (ScriptException e) {
// TODO Auto-generated catch block
log(e.getMessage());
e.printStackTrace(pw);
}
catch (Exception e) {
// TODO Auto-generated catch block
log(e.getMessage());
e.printStackTrace(pw);
}
//
//content = content.replaceAll("#Parameter2#", (String) reportContext.getParameterValue("Parameter2"));
text.setText(content);
}
}