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 display a dynamically created label in a table cell?
s_shetty
Hi,<br />
<br />
I have a problem displaying a dynamically created label in a table cell. My report consists of a table with certain number of columns. The value of one of those columns is obtained by processing the values of two other columns in the same table. I have a java event handler class which extends rowEventAdapter & all the processing logic is within the overridden onCreate() method. My onCreate() method is as follows:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
public void onCreate(IRowInstance row, IReportContext context) {
//Processing logic goes here
//Here 'location' is a String which's obtained from the code above.
ElementFactory ef=context.getReportRunnable().getDesignHandle().getElementFactory();
TableHandle tableHandle =(TableHandle) context.getReportRunnable().getDesignHandle().getModuleHandle().findElement("SampleTable");
RowHandle rowHandle = (RowHandle)tableHandle.getDetail().get(0);
//Get the handle for the column where label has to be displayed
CellHandle sixthCell = (CellHandle) rowHandle.getCells().get(5);
LabelHandle sampleLabel = ef.newLabel("sampleLabel");
try {
sampleLabel.setText(location);
} catch (SemanticException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
sixthCell.getContent().add(sampleLabel);
} catch (ContentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NameException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
</pre>
<br />
<br />
My problem is that, though I have added the label into the sixth cell of my table, it's always blank in my report. I am relatively new to BIRT, so please let me know if I am following the right approach & if yes, what am I missing here.<br />
<br />
Thanks & Regards,<br />
Shreya Shetty
Find more posts tagged with
Comments
mwilliams
Hi Shreya,
You might have to do that in the beforeFactory of your report. If you need dynamic content, you can add the label in the beforeFactory and edit the content in the onCreate of the label.
s_shetty
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="67379" data-time="1281968805" data-date="16 August 2010 - 07:26 AM"><p>
Hi Shreya,<br />
<br />
You might have to do that in the beforeFactory of your report. If you need dynamic content, you can add the label in the beforeFactory and edit the content in the onCreate of the label.<br /></p></blockquote>
<br />
<br />
Hi Michael,<br />
<br />
Thanks for the response.Actually I am quite confused about the right way to achieve this. In a table in my report, I need to display the result of the computations performed on two other columns as a seperate column, in every row.Could you please suggest a best way to do the same?<br />
<br />
Regards,<br />
Shreya
mwilliams
Shreya,
If I'm understanding correctly, that can be done much easier. In your dataSet editor, you can create a computed column that makes a computation based on other columns withing the row. Then this column will be a part of your dataSet and can easily be placed in the table. Let me know if I'm not understanding correctly.
s_shetty
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="67413" data-time="1282047954" data-date="17 August 2010 - 05:25 AM"><p>
Shreya,<br />
<br />
If I'm understanding correctly, that can be done much easier. In your dataSet editor, you can create a computed column that makes a computation based on other columns withing the row. Then this column will be a part of your dataSet and can easily be placed in the table. Let me know if I'm not understanding correctly.<br /></p></blockquote>
<br />
<br />
Michael,<br />
<br />
Yeah, but I guess that can be done only for simpler computations. In my case, the computation is quite complex.<br />
<br />
It consists of the following steps for every row:<br />
<br />
1)Retrieve the value of two of the columns in my table<br />
2)Create an URL with those column values as parameters<br />
3)Use the created URL to access a web service which would send me a text file as part of the response<br />
4)Parse the obtained text file to get a particular value<br />
5)Display the obtained value as a seperate column in the table<br />
<br />
So I think I don't have an option other than using the Java event handlers. Please correct me if I am wrong.<br />
<br />
<br />
Thanks & Regards,<br />
Shreya
mwilliams
Shreya,
You're probably right. If I find anything different out, I'll let you know.
mwilliams
You can use "importPackage" in the expression builder to bring in any java packages you need to do this in the computed column. The only downside will be that your dataSet will take much longer to run. Using event handlers might be faster.
Hope this helps.