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)
Pass Parameter to Scripted Data Set (Event Handler in Java)
evgeny
Hi,
I have created a scripted data set in java. The java class is called through the Event Handler of the data set (Event Handler in the Property Tab of the Data Set).
The java class has the two overridden methods:
public boolean fetch(IDataSetInstance dataSet, IUpdatableDataSetRow row) {
...
}
and
public void open(IDataSetInstance dataSet) {
}
How can I pass a parameter to the Event Handler/ to this class?
Thank you for your reply.
Evgeny
Find more posts tagged with
Comments
evgeny
Hi,<br />
<br />
here is the solution I came up with:<br />
<br />
1.Click on the report name in the Outline view<br />
2.Go to Event Handler<br />
3. Add the ParamSetter as Event Handler<br />
<br />
ParamSetter class:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
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.eventadapter.ReportEventAdapter;
public class ParamSetter extends ReportEventAdapter {
@Override
public void initialize(IReportContext reportContext) {
try {
super.initialize(reportContext);
} catch (ScriptException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//log("in ParamSetter initialize");
Context aContext = ContextManager.getContextInstance();
Parameter parameters = new Parameter();
String aParamList[] = {
"param1",
"param2",
"param3"
};
for (int i=0; i<aParamList.length; i++)
{
if ( (reportContext.getParameterValue(aParamList[i])!=null)
&& (((reportContext.getParameterValue(aParamList[i]))).toString().trim().length()>0)
)
{
parameters.addColumn(aParamList[i], reportContext.getParameterValue(aParamList[i]).toString());
}
}
aContext.setParameters(parameters);
processParameters(reportContext, parameters);
}
public void processParameters(IReportContext reportContext, Parameter parameters){
}
}
}
</pre>
<br />
Here the Context and the Context Manger classes:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
import com.amadeus.ads.birt.io.Context;
public class ContextManager {
private static Context _context = null;
public static Context getContextInstance(){
if (_context==null)
{
_context = new Context();
}
return _context;
}
}
</pre>
<pre class='_prettyXprint _lang-auto _linenums:0'>
public class Context {
/**
*
@param
args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public Parameter parameters;
public void setParameters(Parameter parameters){
this.parameters = parameters;
}
}
</pre>
And the parameter class:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
public class Parameter {
/**
*
@param
args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public static LinkedList<String[]> parameters;
public Parameter(){
parameters = new LinkedList<String[]>();
}
public static void addColumn(String aParam, String paramValue){
String [] dummy = {aParam, paramValue};
parameters.add(dummy);
}
}
</pre>
<br />
Have fun<br />
<br />
Evgeny