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)
Using Library with Repeating Element in DE Code
b2tech
Hello:
Is there a way to use the "same" table element from a BIRT library "multiple" times in one report design by somehow changing the name (on-the-fly) of the element? I can't seem to get this to work with the DE, or is this not even possible. For instance:
DesignElementHandle deh3 = libhan.findElement("Table_HalfWidth");
design.getBody().add(deh3);
.....
DesignElementHandle deh5 = libhan.findElement("Table_HalfWidth");
deh5.setName("Table_HalfWidth_modified");
design.getBody().add(deh5);
I have a need for multiple tables in my report design files that reference the "same" library element. I will also have to change the filter condition of the table query somehow as each table is unique in how it parses up an external CSV file.
I already know that the "name=" of an element has to be unique in the XML report design code, but also what about the "id=" ? When you use the BIRT report Designer GUI and drag across an element from a library- all this is taken care of for you automatically (incremented by 10 I think). How do you mimic this in DE/java code.
BillH
Find more posts tagged with
Comments
jrreid
Yep, you need to generate a new element from the original though as the element always refers to the single copy you got from the library otherwise.<br />
<br />
Heres how I do it in one of my applications:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
// Get the existing element from the library
DesignElementHandle db = this.library.findElement(comp.get("_name"));
// Generate the new element
DesignElementHandle db1 = this.library.getElementFactory().newElementFrom(db, componentName);
// remove the relationship
db1.localize();
// Add to the report
reportHandle.getBody().add(db1);
</pre>
<br />
comp.get("_name") just gives me the element name from a string, and componentName is the new name for the element
b2tech
Thanks for your input jrreid.
I tried your solution but I am still getting an error when running your line:
// Remove the relationship
deh51.localize();
[Note:deh51 is my newly established element representing a "table-within-a-table" coming from the library. The data-set queries ARE the same for both tables)
Considering that the element in the library is a table that is hooked to a data-set (that also comes from the library), is the meaning of this error message:
SEVERE: Invalid value type: birt-report-query1 org.eclipse........metadata.PropertyValueException: The value "birt-report-query1" is invalid with the type "elementRef"....
referring to the fact that you have to manually re-establish "in java code" the query links for each duplicate table that comes from the same original element of a library?? Yikes....
BillH
jrreid
Yep, you pretty much need to loop over and re-establish things from what I found. I copy the dataset in a similar way to the element and then copy the query from one to the other, loop over the column bindings and then add the dataset to the report as well (granted I also modify the parameter value going to the dataset, so you may be able to skip some of the process)
b2tech
OK, now does this seem correct:
open a BIRT library
a.) get the datasource (only 1 in my case)
b.) get the dataset (only 1 in my case)
c.) get the table element needing duplication (my table-within-a-table)
d.) create a new unique element for table element c.)
(ie. DesignElementHandle deh51 = libhan.getElementFactory().newElementFrom(deh5,"Table_HalfWidth_First");
e.) Fix reference to data bindings for BOTH tables in deh51???
f.) run deh51.localize(); <--- do this after e.) correct ???
g.) loop d.-f. for the number of times a duplicate library table is needed in the report.
h.) Add data source to report
Add data set to report
Add tables to report
.....done