Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Read Value of a NamedExpression
haglo
<div>I use eclipse 4.4.1, windows 8.1, java 7 and birt 4.4.1.<br>
I want to make all in java.</div>
<div> </div>
<div>I have a report with a table.</div>
<div>In the table footer I add a Data. Then, in Data Binding, the Expression</div>
<div>Total.sum(row["Column Binding_5"]) with DataType float</div>
<div>In the "Property Editor - Data" I set the name to "Summe"</div>
<div> </div>
<div>I added a TableEventHandler to the table with the following Code</div>
<div> </div>
<div>
<pre class="_prettyXprint _lang-">
public void onRender(ITableInstance arg0, IReportContext arg1)
throws ScriptException {
float tmp = (float) arg0.getNamedExpressionValue("Summe");
if (tmp > 100.0) {
arg0.getStyle().setBackgroundColor("red");
}
}
</pre>
</div>
<div>My Question:</div>
<div>What is here wrong.</div>
<div>It happens nothing.</div>
Find more posts tagged with
Comments
JFreeman
<p>Could you elaborate on nothing happening.</p>
<p> </p>
<p>Does the code run at all or is not being executed?<br>
Do you see your variable tmp getting populated with a value?</p>
<p> </p>
<p>In your if statement, if you examine the output of arg0.getStyle().getBackgroundColor() before an after you set it do you see it changing to "red" like you want?</p>
haglo
<p>I have not set the code into onCreate<br><br>
The following code is running correct<br>
</p>
<pre class="_prettyXprint _lang-">
public void onCreate(ITableInstance arg0, IReportContext arg1)
throws ScriptException {
arg0.getStyle().setBackgroundColor("blue");
}
</pre>
<p>But at the following code happens nothing. When i debug, it jumps to a class TableScriptExecutor.class<br>
</p>
<pre class="_prettyXprint _lang-">
public void onCreate(ITableInstance arg0, IReportContext arg1)
throws ScriptException {
float tmp0 = 0.0f;
tmp0 = (float) arg0.getNamedExpressionValue("Summe");
}
</pre>
JFreeman
<p>Does tmp0 get populated with a value?</p>
<p>What is returned by arg0.getNamedExpressionValue("Summe") if you do not cast it to a float?</p>
haglo
<p>I must cast "arg0.getNamedExpressionValue("Summe")". If i do not, i get an error.</p>
<p> </p>
<p>With the following source i get no exception but the value of tmp1 + tmp2 is "null"</p>
<pre class="_prettyXprint _lang-">
public void onCreate(ITableInstance arg0, IReportContext arg1)
throws ScriptException {
Object tmp1 = (Object) arg0.getNamedExpressionValue("Summe");
Float tmp2 = (Float) arg0.getNamedExpressionValue("Summe");
}
</pre>
<p>When I download the sources of birt and debug it, following happens with the following source:</p>
<pre class="_prettyXprint _lang-">
public void onRender(ITableInstance arg0, IReportContext arg1)
throws ScriptException {
float tmp = (float) arg0.getNamedExpressionValue("Summe");
}
</pre>
<p>I jump to the Class "TableScriptExecutor.java" to the following Method</p>
<pre class="_prettyXprint _lang-">
public static void handleOnCreate( ITableContent content,
ExecutionContext context )
{
ReportItemDesign tableDesign = (ReportItemDesign) content
.getGenerateBy( );
if ( !needOnCreate( tableDesign ) )
{
return;
}
try
{
ITableInstance table = new TableInstance( content, context,
RunningState.CREATE );
if ( handleScript( table, tableDesign.getOnCreate( ), context )
.didRun( ) )
return;
ITableEventHandler eh = getEventHandler( tableDesign, context );
if ( eh != null )
eh.onCreate( table, context.getReportContext( ) );
} catch ( Exception e )
{
addException( context, e, tableDesign.getHandle( ) );
}
}
</pre>
<p>Here it throws the exception </p>
<pre class="_prettyXprint _lang-">
} catch ( Exception e )
{
addException( context, e, tableDesign.getHandle( ) );
}
</pre>
<p>Can it be, that here is a Bug?</p>
<p> </p>
<p> </p>
<p>Question:<br>
Do you know another way with eventhandler to read the "Value of an Expression" after the report is created?<br><br>
</p>
haglo
<p>Can anybody help me?<br>
I have no idea how to solve the problem.</p>